So I have a Leaderboard and I'm trying to save but it doesn't work! I tried on every single save script... No hope.
-- This is Simple Data Persistance for your game :D -- Just put this into the Workspace and you can save multiple scores in your game when -- players enter and leave :) -- WARNING: You need to have leaderstats with at least one stat to be saved in it -- or this script is pointless and won't work :) -- By: CloneTrooper1019 -- Feel free to erase all this green text. I don't care. -- Im just glad you are using my script :) --------Don't edit below unless you know what your doing-------- function onPlayerEntered(player) wait(5)-- Give the game a moment to find the player instead of shooting instantly. player:WaitForDataReady() -- Gotta have this repeat wait(0.01) until player:FindFirstChild("leaderstats") -- waits for the stats. if player.DataReady then -- A little pointless But whatever :) if player:findFirstChild("leaderstats") then local score = player.leaderstats:GetChildren() -- Were going to find some scores. for i = 1,#score do local ScoreLoaded = player:LoadNumber("Halo"..score[i].Name.."") -- This looks for the score. wait() -- Wait for the score to load. if ScoreLoaded ~= 0 then score[i].Value = ScoreLoaded end end end end end function onPlayerLeaving(player) -- We gotta fire this before the player leaves. if player:findFirstChild("leaderstats") then local score = player.leaderstats:children() -- Targeting the scores before the player is gone for i = 1,#score do player:SaveNumber("Halo"..score[i].Name.."", score[i].Value) -- Saving the score. end end end game.Players.PlayerAdded:connect(onPlayerEntered) game.Players.PlayerRemoving:connect(onPlayerLeaving) print("Save system Has been Successfully loaded!")
I am using this.
Script 2:
-- This is Simple Data Persistance for your game :D -- Just put this into the Workspace and you can save multiple scores in your game when -- players enter and leave :) -- WARNING: You need to have leaderstats with at least one stat to be saved in it -- or this script is pointless and won't work :) -- By: CloneTrooper1019 -- Feel free to erase all this green text. I don't care. -- Im just glad you are using my script :) --------Don't edit below unless you know what your doing-------- function onPlayerEntered(player) wait(5)-- Give the game a moment to find the player instead of shooting instantly. player:WaitForDataReady() -- Gotta have this repeat wait(0.01) until player:FindFirstChild("CoinFactor") -- waits for the stats. if player.DataReady then -- A little pointless But whatever :) if player:findFirstChild("CoinFactor") then local score = player.leaderstats:GetChildren() -- Were going to find some scores. for i = 1,#score do local ScoreLoaded = player:LoadNumber("Halo"..score[i].Name.."") -- This looks for the score. wait() -- Wait for the score to load. if ScoreLoaded ~= 0 then score[i].Value = ScoreLoaded end end end end end function onPlayerLeaving(player) -- We gotta fire this before the player leaves. if player:findFirstChild("CoinFactor") then local score = player.leaderstats:children() -- Targeting the scores before the player is gone for i = 1,#score do player:SaveNumber("Halo"..score[i].Name.."", score[i].Value) -- Saving the score. end end end game.Players.PlayerAdded:connect(onPlayerEntered) game.Players.PlayerRemoving:connect(onPlayerLeaving) print("Save system Has been Successfully loaded!")
Can anyone help me getting this to work? Is it a Studio API issue? I dont know.