Advertisement
Sungmingamerpro13

Daycare Wins and Rounds Classic Main Game

Sep 22nd, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. local Players = game:GetService('Players')
  2. local DatastoreService = game:GetService("DataStoreService")
  3. local TeleportService = game:GetService("TeleportService")
  4. local dVersion = 1
  5.  
  6. local WinsDataStore = DatastoreService:GetDataStore('Wins')
  7.  
  8.  
  9. Players.PlayerAdded:Connect(function(Player)
  10.  
  11. local Stats = Instance.new('Folder')
  12. Stats.Name = 'leaderstats'
  13. Stats.Parent = Player
  14.  
  15. local Wins = Instance.new('IntValue')
  16. Wins.Name = 'Wins'
  17. Wins.Parent = Stats
  18.  
  19.  
  20. local Data = WinsDataStore:GetAsync(Player.UserId)
  21.  
  22.  
  23. if Data then
  24. for name, value in pairs(Data.Stats) do
  25. Stats[name].Value = value
  26. end
  27.  
  28. end
  29.  
  30.  
  31.  
  32. end)
  33.  
  34. Players.PlayerRemoving:Connect(function(Player)
  35. local SaveData = {Stats = {}}
  36.  
  37.  
  38.  
  39. for _, stat in pairs(Player.leaderstats:GetChildren()) do
  40. SaveData.Stats[stat.Name] = stat.Value
  41. end
  42.  
  43.  
  44.  
  45.  
  46.  
  47. WinsDataStore:SetAsync(Player.UserId,SaveData)
  48.  
  49.  
  50. end)
  51.  
  52. game:BindToClose(function()
  53. for _, Player in pairs(game.Players:GetPlayers()) do
  54. local SaveData = {Stats = {}}
  55.  
  56.  
  57.  
  58. for _,stat in pairs(Player.leaderstats:GetChildren()) do
  59. SaveData.Stats[stat.Name] = stat.Value
  60. end
  61.  
  62.  
  63.  
  64. WinsDataStore:SetAsync(Player.UserId,SaveData)
  65.  
  66. end
  67.  
  68. wait(2)
  69. end)
  70. local save2 = DatastoreService:GetOrderedDataStore("Rounds "..dVersion)
  71.  
  72. game.Players.PlayerAdded:Connect(function(player)
  73. local previousData = save2:GetAsync(player.UserId) -- Returns a number value.
  74.  
  75. local Rounds
  76.  
  77. if previousData ~= nil then
  78. Rounds = previousData
  79. else
  80. Rounds = 0
  81. save2:SetAsync(player.UserId, 0)
  82. end
  83.  
  84. local coinsValue = Instance.new("IntValue", player)
  85. coinsValue.Name = "Rounds"
  86. coinsValue.Value = Rounds
  87. end)
  88.  
  89. game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
  90. print("STOPPED!")
  91.  
  92. for i,player in pairs(game.Players:GetPlayers()) do
  93. local value = player.Rounds.Value
  94. save2:SetAsync(player.UserId, value)
  95. print("Saved data for "..player.Name)
  96. end
  97. end)
  98.  
  99. game.Players.PlayerRemoving:Connect(function(player)
  100. local value = player.Rounds.Value
  101.  
  102. if value ~= nil then
  103. print("Found data to save for "..player.Name.."!")
  104. save2:SetAsync(player.UserId, value)
  105. print("Saved data for "..player.Name)
  106. else
  107. print("Did not manage to find data to save for "..player.Name.."!")
  108. end
  109. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement