Advertisement
Sungmingamerpro13

My DataStore of Horror Friends Lobby Game

Oct 21st, 2022 (edited)
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local dVersion = 1
  3. local SaveWins = game:GetService("DataStoreService"):GetOrderedDataStore("Wins", dVersion)
  4.  
  5. local VIPGamepass = 94862586
  6.  
  7. game.Players.PlayerAdded:Connect(function(player)
  8. local previousData = SaveWins:GetAsync(player.UserId)
  9.  
  10. local Wins
  11.  
  12. if previousData ~= nil then
  13. Wins = previousData
  14. else
  15. Wins = 0
  16. SaveWins:SetAsync(player.UserId, 0)
  17. end
  18.  
  19. local WinsValue = Instance.new("NumberValue", player)
  20. WinsValue.Name = "Wins"
  21. WinsValue.Value = Wins
  22.  
  23. end)
  24.  
  25. game:BindToClose(function()
  26.  
  27. for i, player in pairs(game.Players:GetPlayers()) do
  28. local Value = player.Wins.Value
  29.  
  30. SaveWins:SetAsync(player.UserId, Value)
  31. end
  32. end)
  33.  
  34. game.Players.PlayerRemoving:Connect(function(player)
  35. local Value = player.Wins.Value
  36.  
  37. if Value ~= nil then
  38. print("Found data to save for "..player.Name.."!")
  39. SaveWins:SetAsync(player.UserId, Value)
  40. print("Saved data for "..player.Name)
  41. else
  42. print("Did not manage to find data to save for "..player.Name.."!")
  43. end
  44. end)
  45.  
  46. local SaveRounds = game:GetService("DataStoreService"):GetOrderedDataStore("Rounds", dVersion)
  47.  
  48. game.Players.PlayerAdded:Connect(function(player)
  49. local previousData = SaveWins:GetAsync(player.UserId)
  50.  
  51. local Rounds
  52.  
  53. if previousData ~= nil then
  54. Rounds = previousData
  55. else
  56. Rounds = 0
  57. SaveRounds:SetAsync(player.UserId, 0)
  58. end
  59.  
  60. local WinsValue = Instance.new("NumberValue", player)
  61. WinsValue.Name = "Rounds"
  62. WinsValue.Value = Rounds
  63.  
  64. end)
  65.  
  66. game:BindToClose(function()
  67.  
  68. for i, player in pairs(game.Players:GetPlayers()) do
  69. local Value = player.Rounds.Value
  70.  
  71. SaveRounds:SetAsync(player.UserId, Value)
  72. end
  73. end)
  74.  
  75. game.Players.PlayerRemoving:Connect(function(player)
  76. local Value = player.Rounds.Value
  77.  
  78. if Value ~= nil then
  79. print("Found data to save for "..player.Name.."!")
  80. SaveRounds:SetAsync(player.UserId, Value)
  81. print("Saved data for "..player.Name)
  82. else
  83. print("Did not manage to find data to save for "..player.Name.."!")
  84. end
  85. end)
  86.  
  87. local SaveLives = game:GetService("DataStoreService"):GetOrderedDataStore("Lives", dVersion)
  88.  
  89. game.Players.PlayerAdded:Connect(function(player)
  90. local previousData = SaveWins:GetAsync(player.UserId)
  91.  
  92. local Lives
  93.  
  94. if previousData ~= nil then
  95. Lives = previousData
  96. else
  97. Lives = 0
  98. SaveLives:SetAsync(player.UserId, 0)
  99. end
  100.  
  101. local WinsValue = Instance.new("NumberValue", player)
  102. WinsValue.Name = "Lives"
  103. WinsValue.Value = Lives
  104.  
  105. end)
  106.  
  107. game:BindToClose(function()
  108.  
  109. for i, player in pairs(game.Players:GetPlayers()) do
  110. local Value = player.Lives.Value
  111.  
  112. SaveLives:SetAsync(player.UserId, Value)
  113. end
  114. end)
  115.  
  116. game.Players.PlayerRemoving:Connect(function(player)
  117. local Value = player.Lives.Value
  118.  
  119. if Value ~= nil then
  120. print("Found data to save for "..player.Name.."!")
  121. SaveLives:SetAsync(player.UserId, Value)
  122. print("Saved data for "..player.Name)
  123. else
  124. print("Did not manage to find data to save for "..player.Name.."!")
  125. end
  126. end)
  127.  
  128. local SaveCoins = game:GetService("DataStoreService"):GetOrderedDataStore("Coins", dVersion)
  129.  
  130. game.Players.PlayerAdded:Connect(function(player)
  131. local previousData = SaveWins:GetAsync(player.UserId)
  132.  
  133. local Coins
  134.  
  135. if previousData ~= nil then
  136. Coins = previousData
  137. else
  138. Coins = 0
  139. SaveCoins:SetAsync(player.UserId, 0)
  140. end
  141.  
  142. local WinsValue = Instance.new("NumberValue", player)
  143. WinsValue.Name = "Coins"
  144. WinsValue.Value = Coins
  145.  
  146. if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPGamepass) then
  147. player.Coins.Value = player.Coins.Value *2
  148. end
  149.  
  150. end)
  151.  
  152. game:BindToClose(function()
  153.  
  154. for i, player in pairs(game.Players:GetPlayers()) do
  155. local Value = player.Coins.Value
  156.  
  157. SaveCoins:SetAsync(player.UserId, Value)
  158. end
  159. end)
  160.  
  161. game.Players.PlayerRemoving:Connect(function(player)
  162. local Value = player.Coins.Value
  163.  
  164. if Value ~= nil then
  165. print("Found data to save for "..player.Name.."!")
  166. SaveCoins:SetAsync(player.UserId, Value)
  167. print("Saved data for "..player.Name)
  168. else
  169. print("Did not manage to find data to save for "..player.Name.."!")
  170. end
  171. end)
  172.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement