Advertisement
brianspy

Untitled

Sep 29th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. --Original layout used for ROBLOX Hiking http://www.roblox.com/--item?id=5462656
  2.  
  3. --you don't need to change anything except where it tells you to
  4.  
  5. function saveScore1(player, score1)
  6. player:SaveNumber("EXP", score1) --change "EXP" to your 1st stat
  7. end
  8.  
  9. function saveScore2(player, score2)
  10. player:SaveNumber("Gold", score2)--change "Gold" to your 2nd stat
  11. end
  12.  
  13. function saveScore3(player, score3)
  14. player:SaveNumber("Ivl", score3)
  15. end
  16.  
  17. function loadScore1(player, money)
  18. local score1 = player:LoadNumber("EXP") --change "EXP" to your 1st stat
  19. local stats = player:FindFirstChild("leaderstats")
  20. if (stats ~= nil) then
  21. local money = stats:FindFirstChild("EXP") --change "EXP" to your 1st stat
  22. money.Value = score1
  23. end
  24. end
  25.  
  26. function loadScore2(player, gold)
  27. local score2 = player:LoadNumber("Gold")
  28. local stats = player:FindFirstChild("leaderstats")
  29. if (stats ~= nil) then
  30. local gold = stats:FindFirstChild("Gold") --change "Gold" to your 2nd stat
  31. gold.Value = score2
  32. end
  33. end
  34.  
  35. function loadScore3(player, lvl)
  36. local score3 = player:LoadNumber("Ivl")
  37. local stats = player:FindFirstChild("leaderstats")
  38. if (stats ~= nil) then
  39. local lvl = stats:FindFirstChild("lvl")
  40. lvl.Value = score3
  41. end
  42. end
  43.  
  44.  
  45. function onPlayerEntered(newPlayer)
  46.  
  47. if newPlayer:findFirstChild("leaderstats") ~= nil then
  48. newPlayer.leaderstats:remove()
  49. end
  50.  
  51. local stats = Instance.new("IntValue")
  52. stats.Name = "leaderstats"
  53. stats.Parent = newPlayer
  54.  
  55. expinsert = Instance.new("IntValue")
  56. expinsert.Parent = stats
  57. expinsert.Name = "EXP" --change "EXP" to your 1st stat
  58. expinsert.Value = 0
  59.  
  60. goldinsert = Instance.new("IntValue")
  61. goldinsert.Parent = stats
  62. goldinsert.Name = "Gold" --change "Gold" to your 2nd stat
  63. goldinsert.Value = 0
  64.  
  65. lvlinsert = Instance.new("IntValue")
  66. lvlinsert.Parent = stats
  67. lvlinsert.Name = "lvl"
  68. lvlinsert.Value = 1 --starting value of a stat
  69.  
  70. print"waiting for data to be ready"
  71. newPlayer:WaitForDataReady() --must have
  72.  
  73. -- loads the player's score
  74. loadScore1(newPlayer, money)
  75. loadScore2(newPlayer, gold)
  76. loadScore3(newPlayer, lvl)
  77.  
  78. end
  79.  
  80. function onPlayerRemoving(player)
  81. print("Attempting to save score for " .. player.Name)
  82. if player.DataReady == true then
  83.  
  84. local stats = player:FindFirstChild("leaderstats")
  85. if (stats ~= nil) then
  86. local money = stats:FindFirstChild("EXP") --change "EXP" to your 1st stat
  87.  
  88. if (money ~= nil) then
  89. saveScore1(player, money.Value)
  90. print("saved money")
  91. end
  92.  
  93. local gold = stats:FindFirstChild("Gold") --change "Gold" to your 2nd stat
  94. if (gold ~= nil) then
  95. saveScore2(player, gold.Value)
  96. print("saved gold")
  97. end
  98. end
  99.  
  100. local lvl = stats:FindFirstChild("lvl")
  101. if (lvl ~= nil) then
  102. saveScore3(player, lvl.Value)
  103. end
  104.  
  105. end
  106. end
  107.  
  108.  
  109. game.Players.PlayerAdded:connect(onPlayerEntered)
  110. game.Players.PlayerRemoving:connect(onPlayerRemoving)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement