When i play a game one value is 10 and the other is 1, i rejoin and both of them are 10
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Money = Instance.new("IntValue",leader)
Money.Name = "Money"
Money.Value = ds:GetAsync(player.UserId) or 0
ds:SetAsync(player.UserId, Money.Value)
leader.Name = "leaderstats"
local tot = Instance.new("IntValue",leader)
tot.Name = "Total"
tot.Value = ds:GetAsync(player.UserId) or 0
ds:SetAsync(player.UserId, tot.Value)
Money.Changed:connect(function()
ds:SetAsync(player.UserId, Money.Value)
tot.Changed:connect(function()
ds:SetAsync(player.UserId, tot.Value)
end)
end)
end)
game.Players.PlayerRemoving:connect(function(player)
ds:SetAsync(player.UserId, player.leaderstats.Total.Value)
ds:SetAsync(player.UserId, player.leaderstats.Money.Value)
end)
