datstore = game:GetService("DataStoreService")
local datast1 = datstore:GetDataStore("Yuan")
local datast2 = datstore:GetDataStore("Gems")
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder",plr)
folder.Name = "leaderstats"
local gems = Instance.new("IntValue",folder)
gems.Name = "Gems"
local cash = Instance.new("IntValue",folder)
cash.Name = "Cash"
gems.Value = datast1:GetAsync(plr.UserId) or 0
datast1:SetAsync(plr.UserId, gems.Value)
cash.Value = datast2:GetAsync(plr.UserId) or 0
datast2:SetAsync(plr.UserId, cash.Value)
gems.Changed:Connect(function()
datast1:SetAsync(plr.UserId, gems.Value)
end)
cash.Changed:Connect(function()
datast2:SetAsync(plr.UserId, cash.Value)
end)
end)
✓ ANSWER ACCEPTED
Why won't this save my leaderboard stats? After I rejoin
1 answer
✓ Accepted answer
You have to activate the API services thingy in your game settings.
This discussion is preserved as it was. New answers, comments, and votes are closed.

9 comments
This code should work, are you getting any errors/warnings ingame? Check /console
No im not getting any errors it just won't save
it should be in a regular script
Its in a serverscript and it is inside ServerScriptService
are you changing gems' value locally or server side
locally
the server cannot tell when a value is changed locally, you'd have to use remote events to tell the server when to update the value
Who downvoted this..?
Note that, unless 'gems' and 'cash' rarely change, you're likely to get throttling problems by calling SetAsync every time they change (at least you might when you have more players in a server than just yourself).