Advertisement
Sungmingamerpro13

My New Horror Friends Story Game DataStore Lobby v2

Nov 13th, 2022 (edited)
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 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 RoundsValue = Instance.new("NumberValue", player)
  61. RoundsValue.Name = "Rounds"
  62. RoundsValue.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 LivesValue = Instance.new("NumberValue", player)
  102. LivesValue.Name = "Lives"
  103. LivesValue.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 CoinsValue = Instance.new("NumberValue", player)
  143. CoinsValue.Name = "Coins"
  144. CoinsValue.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.  
  173. local SaveGems = game:GetService("DataStoreService"):GetOrderedDataStore("Gems", dVersion)
  174.  
  175. game.Players.PlayerAdded:Connect(function(player)
  176. local previousData = SaveGems:GetAsync(player.UserId)
  177.  
  178. local Gems
  179.  
  180. if previousData ~= nil then
  181. Gems = previousData
  182. else
  183. Gems = 0
  184. SaveGems:SetAsync(player.UserId, 0)
  185. end
  186.  
  187. local GemsValue = Instance.new("NumberValue", player)
  188. GemsValue.Name = "Gems"
  189. GemsValue.Value = Gems
  190.  
  191. if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPGamepass) then
  192. player.Gems.Value = player.Gems.Value *2
  193. end
  194.  
  195. end)
  196.  
  197. game:BindToClose(function()
  198.  
  199. for i, player in pairs(game.Players:GetPlayers()) do
  200. local Value = player.Gems.Value
  201.  
  202. SaveGems:SetAsync(player.UserId, Value)
  203. end
  204. end)
  205.  
  206. game.Players.PlayerRemoving:Connect(function(player)
  207. local Value = player.Gems.Value
  208.  
  209. if Value ~= nil then
  210. print("Found data to save for "..player.Name.."!")
  211. SaveGems:SetAsync(player.UserId, Value)
  212. print("Saved data for "..player.Name)
  213. else
  214. print("Did not manage to find data to save for "..player.Name.."!")
  215. end
  216. end)
  217.  
  218. local TeleportData = TeleportService:GetLocalPlayerTeleportData()
  219.  
  220. if TeleportData then
  221. local player = game.Players:GetPlayerByUserId(TeleportData.PlayerName)
  222. player:WaitForChild("Wins").Value = player:WaitForChild("Wins").Value + 1
  223. end
  224.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement