Sungmingamerpro13

New WIns and Rounds DataStore

Mar 10th, 2026
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.90 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local WinsDataStore = game:GetService("DataStoreService"):GetDataStore("Wins")
  3. local RoundsDataStore = game:GetService("DataStoreService"):GetDataStore("Rounds")
  4.  
  5. game.Players.PlayerAdded:Connect(function(player)
  6.     local previousData = WinsDataStore:GetAsync(player.UserId) -- Returns a number value.
  7.     local previousData2 = RoundsDataStore:GetAsync(player.UserId)
  8.    
  9.     local leaderstats = Instance.new("Folder", player)
  10.     leaderstats.Name = "leaderstats"
  11.  
  12.     local Wins
  13.     local Rounds
  14.  
  15.     if previousData ~= nil then
  16.         Wins = previousData
  17.     else
  18.         Wins = 0
  19.         WinsDataStore:SetAsync(player.UserId, 0)
  20.     end
  21.  
  22.     local WinsValue = Instance.new("NumberValue", leaderstats)
  23.     WinsValue.Name = "Wins"
  24.     WinsValue.Value = Wins
  25.    
  26.     if previousData2 ~= nil then
  27.         Rounds = previousData2
  28.     else
  29.         Rounds = 0
  30.         RoundsDataStore:SetAsync(player.UserId, 0)
  31.     end
  32.  
  33.     local RoundsValue = Instance.new("NumberValue", leaderstats)
  34.     RoundsValue.Name = "Rounds"
  35.     RoundsValue.Value = Rounds
  36.    
  37. end)
  38.  
  39. game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
  40.     print("STOPPED!")
  41.  
  42.     for i,player in pairs(game.Players:GetPlayers()) do
  43.         local value = player.leaderstats.Wins.Value
  44.         local value2 = player.leaderstats.Rounds.Value
  45.        
  46.         WinsDataStore:SetAsync(player.UserId, value)
  47.         RoundsDataStore:SetAsync(player.UserId, value2)
  48.         print("Saved data for "..player.Name)
  49.     end
  50. end)
  51.  
  52. game.Players.PlayerRemoving:Connect(function(player)
  53.     local value = player.leaderstats.Wins.Value
  54.     local value2 = player.leaderstats.Rounds.Value
  55.  
  56.     if value ~= nil and value2 ~= nil then
  57.         print("Found data to save for "..player.Name.."!")
  58.         WinsDataStore:SetAsync(player.UserId, value)
  59.         RoundsDataStore:SetAsync(player.UserId, value2)
  60.         print("Saved data for "..player.Name)
  61.     else
  62.         print("Did not manage to find data to save for "..player.Name.."!")
  63.     end
  64. end)
  65.  
Advertisement
Add Comment
Please, Sign In to add comment