Sungmingamerpro13

WinsDataStore

Feb 21st, 2026
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.15 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local players = game:GetService('Players')
  3. local dataStoreService = game:GetService('DataStoreService')
  4.  
  5. local saveDataStore = dataStoreService:GetDataStore("SaveData")
  6.  
  7. players.PlayerAdded:Connect(function(plr)
  8.  
  9.     local stats = Instance.new('Folder')
  10.     stats.Name = 'leaderstats'
  11.     stats.Parent = plr
  12.  
  13.     local Wins = Instance.new('IntValue')
  14.     Wins.Name = 'Wins'
  15.     Wins.Parent = stats
  16.  
  17.     local data = saveDataStore:GetAsync(plr.UserId)
  18.  
  19.     if data then
  20.  
  21.         for name, value in pairs(data.Stats) do
  22.  
  23.             stats[name].Value = value
  24.         end
  25.     end
  26.  
  27.  
  28.  
  29. end)
  30.  
  31. players.PlayerRemoving:Connect(function(plr)
  32.  
  33.     local saveData = {Stats = {}}
  34.  
  35.     for _,stat in pairs(plr.leaderstats:GetChildren()) do
  36.  
  37.         saveData.Stats[stat.Name] = stat.Value
  38.  
  39.     end
  40.  
  41.     saveDataStore:SetAsync(plr.UserId,saveData)
  42.  
  43. end)
  44.  
  45. game:BindToClose(function()
  46.  
  47.     for _,plr in pairs(players:GetChildren()) do
  48.  
  49.         local saveData = {Stats = {}}
  50.  
  51.         for _,stat in pairs(plr.leaderstats:GetChildren()) do
  52.  
  53.             saveData.Stats[stat.Name] = stat.Value
  54.  
  55.         end
  56.  
  57.         saveDataStore:SetAsync(plr.UserId, saveData)
  58.  
  59.     end
  60.  
  61.     wait(2)
  62.  
  63. end)
  64.  
Advertisement
Add Comment
Please, Sign In to add comment