I've been trying to study on how this datastore system works, I'm still a bit stuck on this saving script. This is what I got.
local DataStore = game:GetService("DataStoreService")
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Cash = Instance.new("IntValue",leader)
Cash.Name = "Cash"
Cash.Value = ds:GetAsync(player.UserId) or 0
ds:SetAsync(player.UserId, Cash.Value)
Cash.Changed:connect(function()
ds:SetAsync(player.UserId, Cash.Value)
end)
game.Players.PlayerRemoving:connect(function(player)
ds:SetAsync(player.UserId, player.leaderstats.Cash.Value)
end)
It would really be helpful if you could help me :D

1 comment
Thank you, I think Pcalls make it so if the function breaks it won't break the entire script, very helpful!