Here are my scripts. If you find any errors can you correct them in the answers? Thanks leaderstats script- game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player
local cash = Instance.new("IntValue") cash.Name ="Cash" cash.Value = 0 cash.Parent = leaderstats
end) DataStore script- local ds = game:GetService("DataStoreService"):GetDataStore("SaveData") game.Players.PlayerAdded:Connect(function(plr) wait() local plrkey = "id_"..plr.userId local save1 = plr.leaderstats.Cash
local GetSaved = ds:GetAsync(plrkey) if GetSaved then save1.Value = GetSaved[1] else local NumberForSaving = {save1.Value} ds:GetAsync(plrkey,NumberForSaving) end
end)
game.Players.PlayerRemoving:Connect(function(plr) ds:SetAsync("id_"..plr.userId,{plr.leaderstats.Cash.Value}) end)
Try this script and let me know does it work!
local players = game:GetService("Players") local ds=game:GetService("CashSave") players.PlayerAdded:connect(function(player) local folder = Instance.new("Folder") folder.Name = "leaderstats" folder.Parent = player local currency1 = Instance.new("IntValue") currency1.Name = "Cash" currency1.Parent = player.leaderstats currency1.Value = ds:GetAsync(player.UserId) or 0 ds:SetAsync(player.UserId, currency1.Value) currency1.Changed:connect(function() ds:SetAsync(player.UserId, currency1.Value) end) end)