Advertisement
Jackthehunter25

Untitled

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