Sungmingamerpro13

My New Leaderstats (Main Game)

Jul 25th, 2025
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 2.78 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local AddWinsDataStore = game:GetService("DataStoreService"):GetDataStore("AddWins")
  3.  
  4. game.Players.PlayerAdded:Connect(function(player)
  5.     local previousData = AddWinsDataStore:GetAsync(player.UserId) -- Returns a number value.
  6.  
  7.     local AddWins
  8.  
  9.     if previousData ~= nil then
  10.         AddWins = previousData
  11.     else
  12.         AddWins = 0
  13.         AddWinsDataStore:SetAsync(player.UserId, 0)
  14.     end
  15.  
  16.     local coinsValue = Instance.new("IntValue", player)
  17.     coinsValue.Name = "AddWins"
  18.     coinsValue.Value = AddWins
  19. end)
  20.  
  21. game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
  22.     print("STOPPED!")
  23.  
  24.     for i,player in pairs(game.Players:GetPlayers()) do
  25.         local value = player.AddWins.Value
  26.         AddWinsDataStore:SetAsync(player.UserId, value)
  27.         print("Saved data for "..player.Name)
  28.     end
  29. end)
  30.  
  31. game.Players.PlayerRemoving:Connect(function(player)
  32.     local value = player.AddWins.Value
  33.  
  34.     if value ~= nil then
  35.         print("Found data to save for "..player.Name.."!")
  36.         AddWinsDataStore:SetAsync(player.UserId, value)
  37.         print("Saved data for "..player.Name)
  38.     else
  39.         print("Did not manage to find data to save for "..player.Name.."!")
  40.     end
  41. end)
  42.  
  43. local AddRoundsDataStore = game:GetService("DataStoreService"):GetDataStore("AddRounds")
  44. local RoundsDataStore = game:GetService("DataStoreService"):GetOrderedDataStore("Rounds")
  45.  
  46. game.Players.PlayerAdded:Connect(function(player)
  47.     local previousData = AddRoundsDataStore:GetAsync(player.UserId) -- Returns a number value.
  48.  
  49.     local AddRounds
  50.  
  51.     if previousData ~= nil then
  52.         AddRounds = previousData
  53.     else
  54.         AddRounds = 0
  55.         AddRoundsDataStore:SetAsync(player.UserId, 0)
  56.     end
  57.  
  58.     local coinsValue = Instance.new("IntValue", player)
  59.     coinsValue.Name = "AddRounds"
  60.     coinsValue.Value = AddRounds
  61. end)
  62.  
  63. game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
  64.     print("STOPPED!")
  65.  
  66.     for i,player in pairs(game.Players:GetPlayers()) do
  67.         local value = player.AddRounds.Value
  68.         AddRoundsDataStore:SetAsync(player.UserId, value)
  69.         print("Saved data for "..player.Name)
  70.     end
  71. end)
  72.  
  73. game.Players.PlayerRemoving:Connect(function(player)
  74.     local value = player.AddRounds.Value
  75.  
  76.     if value ~= nil then
  77.         print("Found data to save for "..player.Name.."!")
  78.         AddRoundsDataStore:SetAsync(player.UserId, value)
  79.         print("Saved data for "..player.Name)
  80.     else
  81.         print("Did not manage to find data to save for "..player.Name.."!")
  82.     end
  83. end)
  84.  
  85. game.Players.PlayerAdded:Connect(function(player)
  86.     player.CharacterAdded:Connect(function(Character)
  87.         Character.Died:Connect(function()
  88.             RoundsDataStore:IncrementAsync(player.UserId, 1)
  89.             AddRoundsDataStore:SetAsync(player.UserId, player.AddRounds.Value)
  90.             player.AddRounds.Value = player.AddRounds.Value + 1
  91.         end)
  92.     end)
  93. end)
  94.  
Advertisement
Add Comment
Please, Sign In to add comment