Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why won't this save my leaderboard stats? After I rejoin


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)


9 comments

0

This code should work, are you getting any errors/warnings ingame? Check /console

0

No im not getting any errors it just won't save

1

it should be in a regular script

0

Its in a serverscript and it is inside ServerScriptService

0

are you changing gems' value locally or server side

0

locally

0

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

0

Who downvoted this..?

0

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).

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.