Advertisement
Sungmingamerpro13

My Third DataStore Story Game (Main)

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