How to Script on Roblox (ADVANCED) - Part 4 (DataStoreService)

Channel:
Subscribers:
98,500
Published on ● Video Link: https://www.youtube.com/watch?v=rzVMsC0tKRM



Roblox
Game:
Roblox (2006)
Category:
Tutorial
Duration: 18:14
6,390 views
165


Thanks for watching, hope you find DataStoreService helpful! :)

If you want to learn how to Save Data in Roblox Studio, then you're in the perfect place!

BEGINNER Scripting Series: https://www.youtube.com/playlist?list=PLfAg6nOoAuSm3IFHTbLfknrEDnRoSxCwW

SCRIPT -[

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("leaderstats")



game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder",plr)
folder.Name = "leaderstats"

local Coins = Instance.new("IntValue",folder)
Coins.Name = "Coins"

local Gems = Instance.new("IntValue",folder)
Gems.Name = "Gems"

local CoinsVal = 0
local GemsVal = 0

local success,errorMessage = pcall(function()
local data = DataStore:GetAsync(plr.UserId)

CoinsVal = data[1]
GemsVal = data[2]
end)
if success then
print("Data successfully loaded!")
end
if errorMessage then
warn(errorMessage)
end
Coins.Value = CoinsVal
Gems.Value = GemsVal

while true do

task.wait(1)
Coins.Value += 1

end
end)

game.Players.PlayerRemoving:Connect(function(plr)
local coins = plr.leaderstats.Coins
local gems = plr.leaderstats.Gems

DataStore:SetAsync(plr.UserId,{coins.Value,gems.Value})
end)

game:BindToClose(function()
for i,plr in pairs(game.Players:GetPlayers()) do
local coins = plr.leaderstats.Coins
local gems = plr.leaderstats.Gems

DataStore:SetAsync(plr.UserId,{coins.Value,gems.Value})
end
end)

]

✨Discord Server: https://discord.gg/2b6PDk7BAP
😍Patreon: https://www.patreon.com/CodeBro29
👕MERCH: https://codebro29-official-merch.creator-spring.com

💬Comment ideas for future videos below! VVV


Roblox username: fiveironfan2006


My group: https://www.roblox.com/groups/5646843/Codebro29-Industries#!/about

#roblox #coding #lua







Tags:
roblox
roblox scripting tutorial
how to script on roblox for beginners
roblox studio
how to save data in roblox
roblox data
roblox data saving
roblox datastore
roblox datastore tutorial
roblox tutorial
easy coding
coding easy



Other Statistics

Roblox Statistics For CodeBro29

Currently, CodeBro29 has 4,971,613 views for Roblox across 155 videos. There's over 2 days worth of watchable video for Roblox published on his channel, roughly 85.46% of the content that CodeBro29 has uploaded to YouTube.