I have a script supposed to save your leaderstats. I have api services enabled.
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 save2 = plr.leaderstats.Strength
local GetSaved = DS:GetAsync(plrkey)
if GetSaved then
save1.Value = GetSaved[1]
save2.Value = GetSaved[2]
else
local NumberForSaving = {save1.Value, save2.Value}
Also, if you don’t mind, would you add formatting and indentation to your code? It makes it a lot easier for us to read and understand.
This:
```lua
– code
```
Becomes:
Just a note, Roblox Studio is kind of bugged and data doesn’t actually save consistently, so I suggest you to test on the actual Roblox server as see if it works.
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 save2 = plr.leaderstats.Strength
local GetSaved = DS:GetAsync(plrkey)
if GetSaved then
save1.Value = GetSaved[1]
save2.Value = GetSaved[2]
else
local NumberForSaving = {save1.Value, save2.Value}
DS:GetAsync(plrkey)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
DS:SetAsync("id_"..plr.userId,{plr.leaderstats.Strength.Value, plr.leaderstats.Cash.Value})
end)