Advertisement
Newwy

Untitled

Jan 18th, 2018
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --If this doesn't work, I'm sorry. It should though.
  2.  
  3. function saveScore(player, score)
  4. player:SaveNumber("Medals", score)
  5. end
  6.  
  7.  
  8. function loadScore(player, killCounter)
  9. local score = player:LoadNumber("Medals")
  10.  
  11. if score ~= 0 then
  12. killCounter.Value = score
  13. else
  14. print("Nothing to load/score was 0")
  15. end
  16.  
  17. end
  18.  
  19. function onPlayerEntered(newPlayer)
  20.  
  21.  
  22.  
  23. local stats = Instance.new("IntValue")
  24. stats.Name = "leaderstats"
  25.  
  26. local clicks = Instance.new("IntValue")
  27. clicks.Name = "Medals"
  28. clicks.Value = 0
  29.  
  30.  
  31. clicks.Parent = stats
  32. stats.Parent = newPlayer
  33. wait(0.5)
  34. stats.Parent.PlayerGui.welcome.Opening.Visible = true
  35. stats.Parent.PlayerGui.pick.countries.Visible = true
  36. newPlayer:WaitForDataReady()
  37. loadScore(newPlayer, clicks)
  38.  
  39.  
  40. end
  41.  
  42. function onPlayerRemoving(player)
  43. print("Attempting to save score for " .. player.Name)
  44. local stats = player:FindFirstChild("leaderstats")
  45. if (stats ~= nil) then
  46. local clicks = stats:FindFirstChild("Medals")
  47. if (clicks ~= nil) then
  48. saveScore(player, clicks.Value)
  49. end
  50. end
  51. end
  52.  
  53. game.Players.PlayerAdded:connect(onPlayerEntered)
  54. game.Players.PlayerRemoving:connect(onPlayerRemoving)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement