Advertisement
Sungmingamerpro13

STORY GAME Lobby Leaderboard

Oct 15th, 2022 (edited)
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 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. local VIPGamepass = 0
  6.  
  7. game.Players.PlayerAdded:Connect(function(player)
  8. local previousData = SaveWins:GetAsync(player.UserId)
  9.  
  10. local Wins
  11.  
  12. if previousData ~= nil then
  13. Wins = previousData
  14. else
  15. Wins = 0
  16. SaveWins:SetAsync(player.UserId, 0)
  17. end
  18.  
  19. local WinsValue = Instance.new("NumberValue", player)
  20. WinsValue.Name = "Wins"
  21. WinsValue.Value = Wins
  22.  
  23. end)
  24.  
  25. game:BindToClose(function()
  26.  
  27. for i, player in pairs(game.Players:GetPlayers()) do
  28. local Value = player.Wins.Value
  29.  
  30. SaveWins:SetAsync(player.UserId, Value)
  31. end
  32. end)
  33.  
  34. game.Players.PlayerRemoving:Connect(function(player)
  35. local Value = player.Wins.Value
  36.  
  37. if Value ~= nil then
  38. print("Found data to save for "..player.Name.."!")
  39. SaveWins:SetAsync(player.UserId, Value)
  40. print("Saved data for "..player.Name)
  41. else
  42. print("Did not manage to find data to save for "..player.Name.."!")
  43. end
  44. end)
  45.  
  46. local SaveRounds = game:GetService("DataStoreService"):GetOrderedDataStore("Rounds", dVersion)
  47.  
  48. game.Players.PlayerAdded:Connect(function(player)
  49. local previousData = SaveWins:GetAsync(player.UserId)
  50.  
  51. local Rounds
  52.  
  53. if previousData ~= nil then
  54. Rounds = previousData
  55. else
  56. Rounds = 0
  57. SaveRounds:SetAsync(player.UserId, 0)
  58. end
  59.  
  60. local WinsValue = Instance.new("NumberValue", player)
  61. WinsValue.Name = "Rounds"
  62. WinsValue.Value = Rounds
  63.  
  64. end)
  65.  
  66. game:BindToClose(function()
  67.  
  68. for i, player in pairs(game.Players:GetPlayers()) do
  69. local Value = player.Rounds.Value
  70.  
  71. SaveRounds:SetAsync(player.UserId, Value)
  72. end
  73. end)
  74.  
  75. game.Players.PlayerRemoving:Connect(function(player)
  76. local Value = player.Rounds.Value
  77.  
  78. if Value ~= nil then
  79. print("Found data to save for "..player.Name.."!")
  80. SaveRounds:SetAsync(player.UserId, Value)
  81. print("Saved data for "..player.Name)
  82. else
  83. print("Did not manage to find data to save for "..player.Name.."!")
  84. end
  85. end)
  86.  
  87. local SaveCoins = game:GetService("DataStoreService"):GetOrderedDataStore("Coins", dVersion)
  88.  
  89. game.Players.PlayerAdded:Connect(function(player)
  90. local previousData = SaveWins:GetAsync(player.UserId)
  91.  
  92. local Coins
  93.  
  94. if previousData ~= nil then
  95. Coins = previousData
  96. else
  97. Coins = 0
  98. SaveCoins:SetAsync(player.UserId, 0)
  99. end
  100.  
  101. local WinsValue = Instance.new("NumberValue", player)
  102. WinsValue.Name = "Coins"
  103. WinsValue.Value = Coins
  104.  
  105. if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPGamepass) then
  106. player.Coins.Value = player.Coins.Value *2
  107. end
  108.  
  109. end)
  110.  
  111. game:BindToClose(function()
  112.  
  113. for i, player in pairs(game.Players:GetPlayers()) do
  114. local Value = player.Coins.Value
  115.  
  116. SaveCoins:SetAsync(player.UserId, Value)
  117. end
  118. end)
  119.  
  120. game.Players.PlayerRemoving:Connect(function(player)
  121. local Value = player.Coins.Value
  122.  
  123. if Value ~= nil then
  124. print("Found data to save for "..player.Name.."!")
  125. SaveCoins:SetAsync(player.UserId, Value)
  126. print("Saved data for "..player.Name)
  127. else
  128. print("Did not manage to find data to save for "..player.Name.."!")
  129. end
  130. end)
  131.  
  132. local TeleportData = TeleportService:GetLocalPlayerTeleportData()
  133.  
  134. if TeleportData then
  135. local player = game.Players:GetPlayerByUserId(TeleportData.PlayerName)
  136. player:WaitForChild("Wins").Value = player:WaitForChild("Wins").Value + 1
  137. end
  138.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement