Advertisement
kanata1000

ROBLOX Data Persistence Script For LeaderBoard

May 21st, 2013
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. -- Read the description of the model for details, it pretty much says to just put it in.
  2.  
  3.  
  4. function onPlayerEntered(player)
  5. wait()-- Change to wait for player longer.
  6. player:WaitForDataReady()
  7. repeat wait() until player:FindFirstChild("leaderstats")
  8. if player.DataReady then
  9. if player:findFirstChild("leaderstats") then
  10. local score = player.leaderstats:GetChildren()
  11. for i = 1,#score do
  12. local ScoreLoaded = player:LoadNumber(score[i].Name)
  13. wait()
  14. if ScoreLoaded ~= 0 then
  15. score[i].Value = ScoreLoaded
  16. end
  17. end
  18. end
  19. end
  20. end
  21.  
  22. function onPlayerLeaving(player)
  23. if player:findFirstChild("leaderstats") then
  24. local score = player.leaderstats:GetChildren()
  25. for i = 1,#score do
  26. player:SaveNumber(score[i].Name,score[i].Value)
  27. end
  28. end
  29. end
  30.  
  31. game.Players.PlayerAdded:connect(onPlayerEntered)
  32. game.Players.PlayerRemoving:connect(onPlayerLeaving)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement