Sungmingamerpro13

STORY GAME Main Leaderboard

Oct 14th, 2022
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local dVersion = 1
  3. local SaveWins = game:GetService("DataStoreService"):GetOrderedDataStore("Wins", dVersion)
  4.  
  5. game.Players.PlayerAdded:Connect(function(player)
  6. local previousData = SaveWins:GetAsync(player.UserId)
  7.  
  8. local Wins
  9.  
  10. if previousData ~= nil then
  11. Wins = previousData
  12. else
  13. Wins = 0
  14. SaveWins:SetAsync(player.UserId, 0)
  15. end
  16.  
  17. local WinsValue = Instance.new("NumberValue", player)
  18. WinsValue.Name = "Wins"
  19. WinsValue.Value = Wins
  20.  
  21. end)
  22.  
  23. game:BindToClose(function()
  24.  
  25. for i, player in pairs(game.Players:GetPlayers()) do
  26. local Value = player.Wins.Value
  27.  
  28. SaveWins:SetAsync(player.UserId, Value)
  29. end
  30. end)
  31.  
  32. game.Players.PlayerRemoving:Connect(function(player)
  33. local Value = player.Wins.Value
  34.  
  35. if Value ~= nil then
  36. print("Found data to save for "..player.Name.."!")
  37. SaveWins:SetAsync(player.UserId, Value)
  38. print("Saved data for "..player.Name)
  39. else
  40. print("Did not manage to find data to save for "..player.Name.."!")
  41. end
  42. end)
Add Comment
Please, Sign In to add comment