So I am making a cash leaderboard with a Data store. Now when I test it, it doesn't work. It works before but now it doesn't. Here is the script:
-- Savable leaderboard? local ds = game:GetService("DataStoreService"):GetDataStore("Cash1112") game.Players.PlayerAdded:Connect(function(player) local key = "cash-"..player.userId local folder = Instance.new("Folder",player) folder.Name = "leaderstats" -- Must be lowercase local currency = Instance.new("IntValue",folder) currency.Name = "Cash" -- Name of your currency currency.Value = 0 -- Starting Cash local save = ds:GetAsync(key) if save then currency.Value = save[1] else local tab = {currency.Value} ds:SetAsync(key,tab) end end) game.Players.PlayerRemoving:Connect(function(player) local key = "cash-"..player.userId local currency = player.leaderstats:FindFirstChild("Cash") -- Currency name. Must match with the top local tab = {currency.Value} ds:SetAsync(key,tab) end)
Thanks.
I have a separate script for the actual leaderboard but I use this script in ServerScriptStorage and it's been working if this helps at all...
function onPlayerEntered(player) wait()-- Change to wait for player longer. player:WaitForDataReady() repeat wait() until player:FindFirstChild("leaderstats") if player.DataReady then if player:findFirstChild("leaderstats") then local score = player.leaderstats:GetChildren() for i = 1,#score do local ScoreLoaded = player:LoadNumber(score[i].Name) wait() if ScoreLoaded ~= 0 then score[i].Value = ScoreLoaded end end end end end function onPlayerLeaving(player) if player:findFirstChild("leaderstats") then local score = player.leaderstats:GetChildren() for i = 1,#score do player:SaveNumber(score[i].Name,score[i].Value) end end end game.Players.PlayerAdded:connect(onPlayerEntered) game.Players.PlayerRemoving:connect(onPlayerLeaving)