Sungmingamerpro13

Story Game Datastore New Lobby Game

Sep 22nd, 2021 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 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)
  110. local CoinsSave = DatastoreService:GetOrderedDataStore("Coins "..dVersion)
  111.  
  112. game.Players.PlayerAdded:Connect(function(player)
  113. local previousData = CoinsSave:GetAsync(player.UserId) -- Returns a number value.
  114.  
  115. local Coins
  116.  
  117. if previousData ~= nil then
  118. Coins = previousData
  119. else
  120. Coins = 0
  121. CoinsSave:SetAsync(player.UserId, 0)
  122. end
  123.  
  124. local coinsValue = Instance.new("IntValue", player)
  125. coinsValue.Name = "Coins"
  126. coinsValue.Value = Coins
  127.  
  128. local val1 = Instance.new("StringValue",player)
  129. val1.Name = 'GotPet'
  130. val1.Value = ''
  131.  
  132. local val2 = Instance.new("StringValue",player)
  133. val2.Name = 'OpenValue'
  134. val2.Value = ''
  135. end)
  136.  
  137. game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
  138. print("STOPPED!")
  139.  
  140. for i,player in pairs(game.Players:GetPlayers()) do
  141. local value = player.Coins.Value
  142. CoinsSave:SetAsync(player.UserId, value)
  143. print("Saved data for "..player.Name)
  144. end
  145. end)
  146.  
  147. game.Players.PlayerRemoving:Connect(function(player)
  148. local value = player.Coins.Value
  149.  
  150. if value ~= nil then
  151. print("Found data to save for "..player.Name.."!")
  152. CoinsSave:SetAsync(player.UserId, value)
  153. print("Saved data for "..player.Name)
  154. else
  155. print("Did not manage to find data to save for "..player.Name.."!")
  156. end
  157. end)
  158. local teleportData = TeleportService:GetLocalPlayerTeleportData()
  159.  
  160. if teleportData then
  161. local Player = game.Players:GetPlayerByUserId(teleportData.PlayerName)
  162. Player:WaitForChild('leaderstats'):WaitForChild('Wins').Value = Player.leaderstats.Wins.Value + 1
  163. end
  164.  
Add Comment
Please, Sign In to add comment