Advertisement
Sungmingamerpro13

Technobrother Datastore Story Game(Main Game)

Aug 14th, 2022
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local dVersion = 1
  3. local save = game:GetService("DataStoreService"):GetOrderedDataStore("Wins "..dVersion)
  4.  
  5. game.Players.PlayerAdded:Connect(function(player)
  6. local previousData = save:GetAsync(player.UserId) -- Returns a number value.
  7.  
  8. local Wins
  9.  
  10. if previousData ~= nil then
  11. Wins = previousData
  12. else
  13. Wins = 0
  14. save:SetAsync(player.UserId, 0)
  15. end
  16.  
  17. local coinsValue = Instance.new("IntValue", player)
  18. coinsValue.Name = "Wins"
  19. coinsValue.Value = Wins
  20. end)
  21.  
  22. game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
  23. print("STOPPED!")
  24.  
  25. for i,player in pairs(game.Players:GetPlayers()) do
  26. local value = player.Wins.Value
  27. save:SetAsync(player.UserId, value)
  28. print("Saved data for "..player.Name)
  29. end
  30. end)
  31.  
  32. game.Players.PlayerRemoving:Connect(function(player)
  33. local value = player.Wins.Value
  34.  
  35. if value ~= nil then
  36. print("Found data to save for "..player.Name.."!")
  37. save:SetAsync(player.UserId, value)
  38. print("Saved data for "..player.Name)
  39. else
  40. print("Did not manage to find data to save for "..player.Name.."!")
  41. end
  42. end)
  43.  
  44. local save2 = game:GetService("DataStoreService"):GetOrderedDataStore("Rounds "..dVersion)
  45.  
  46. game.Players.PlayerAdded:Connect(function(player)
  47. local previousData = save2:GetAsync(player.UserId) -- Returns a number value.
  48.  
  49. local Rounds
  50.  
  51. if previousData ~= nil then
  52. Rounds = previousData
  53. else
  54. Rounds = 0
  55. save2:SetAsync(player.UserId, 0)
  56. end
  57.  
  58. local coinsValue = Instance.new("IntValue", player)
  59. coinsValue.Name = "Rounds"
  60. coinsValue.Value = Rounds
  61. end)
  62.  
  63. game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
  64. print("STOPPED!")
  65.  
  66. for i,player in pairs(game.Players:GetPlayers()) do
  67. local value = player.Rounds.Value
  68. save2:SetAsync(player.UserId, value)
  69. print("Saved data for "..player.Name)
  70. end
  71. end)
  72.  
  73. game.Players.PlayerRemoving:Connect(function(player)
  74. local value = player.Rounds.Value
  75.  
  76. if value ~= nil then
  77. print("Found data to save for "..player.Name.."!")
  78. save2:SetAsync(player.UserId, value)
  79. print("Saved data for "..player.Name)
  80. else
  81. print("Did not manage to find data to save for "..player.Name.."!")
  82. end
  83. end)
  84.  
  85. local CoinsSave = game:GetService("DataStoreService"):GetOrderedDataStore("Coins "..dVersion)
  86.  
  87. game.Players.PlayerAdded:Connect(function(player)
  88. local previousData = CoinsSave:GetAsync(player.UserId) -- Returns a number value.
  89.  
  90. local Coins
  91.  
  92. if previousData ~= nil then
  93. Coins = previousData
  94. else
  95. Coins = 0
  96. CoinsSave:SetAsync(player.UserId, 0)
  97. end
  98.  
  99. local coinsValue = Instance.new("IntValue", player)
  100. coinsValue.Name = "Coins"
  101. coinsValue.Value = Coins
  102.  
  103. local val1 = Instance.new("StringValue",player)
  104. val1.Name = 'GotPet'
  105. val1.Value = ''
  106.  
  107. local val2 = Instance.new("StringValue",player)
  108. val2.Name = 'OpenValue'
  109. val2.Value = ''
  110. end)
  111.  
  112. game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
  113. print("STOPPED!")
  114.  
  115. for i,player in pairs(game.Players:GetPlayers()) do
  116. local value = player.Coins.Value
  117. CoinsSave:SetAsync(player.UserId, value)
  118. print("Saved data for "..player.Name)
  119. end
  120. end)
  121.  
  122. game.Players.PlayerRemoving:Connect(function(player)
  123. local value = player.Coins.Value
  124.  
  125. if value ~= nil then
  126. print("Found data to save for "..player.Name.."!")
  127. CoinsSave:SetAsync(player.UserId, value)
  128. print("Saved data for "..player.Name)
  129. else
  130. print("Did not manage to find data to save for "..player.Name.."!")
  131. end
  132. end)
  133.  
  134. local MoneySave = game:GetService("DataStoreService"):GetOrderedDataStore("Money "..dVersion)
  135.  
  136. game.Players.PlayerAdded:Connect(function(player)
  137. local previousData = MoneySave:GetAsync(player.UserId) -- Returns a number value.
  138.  
  139. local Money
  140.  
  141. if previousData ~= nil then
  142. Money = previousData
  143. else
  144. Money = 0
  145. save2:SetAsync(player.UserId, 0)
  146. end
  147.  
  148. local coinsValue = Instance.new("IntValue", player)
  149. coinsValue.Name = "Money"
  150. coinsValue.Value = Money
  151. end)
  152.  
  153. game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
  154. print("STOPPED!")
  155.  
  156. for i,player in pairs(game.Players:GetPlayers()) do
  157. local value = player.Money.Value
  158. MoneySave:SetAsync(player.UserId, value)
  159. print("Saved data for "..player.Name)
  160. end
  161. end)
  162.  
  163. game.Players.PlayerRemoving:Connect(function(player)
  164. local value = player.Money.Value
  165.  
  166. if value ~= nil then
  167. print("Found data to save for "..player.Name.."!")
  168. MoneySave:SetAsync(player.UserId, value)
  169. print("Saved data for "..player.Name)
  170. else
  171. print("Did not manage to find data to save for "..player.Name.."!")
  172. end
  173. end)
  174.  
  175. game.Players.PlayerAdded:Connect(function(player)
  176. player.CharacterAdded:Connect(function(char)
  177.  
  178. char.Humanoid.Died:Connect(function()
  179. save2:SetAsync(player.UserId, player.Rounds.Value)
  180. player.Rounds.Value = player.Rounds.Value + 1
  181. end)
  182. end)
  183. end)
  184.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement