Advertisement
Sungmingamerpro13

My Third DataStore Story Game (Lobby)

Dec 8th, 2024
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 4.15 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 RoundsValue = Instance.new("IntValue", player)
  20.     RoundsValue.Name = "Wins"
  21.     RoundsValue.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 LivesSave = game:GetService("DataStoreService"):GetDataStore("Lives")
  48.  
  49. game.Players.PlayerAdded:Connect(function(player)
  50.     local previousData = LivesSave:GetAsync(player.UserId) -- Returns a number value.
  51.  
  52.     local Lives
  53.  
  54.     if previousData ~= nil then
  55.         Lives = previousData
  56.     else
  57.         Lives = 0
  58.         LivesSave:SetAsync(player.UserId, 0)
  59.     end
  60.  
  61.     local LivesValue = Instance.new("IntValue", player)
  62.     LivesValue.Name = "Lives"
  63.     LivesValue.Value = Lives
  64.    
  65. end)
  66.  
  67. game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
  68.     print("STOPPED!")
  69.  
  70.     for i,player in pairs(game.Players:GetPlayers()) do
  71.         local value = player.Lives.Value
  72.         LivesSave:SetAsync(player.UserId, value)
  73.         print("Saved data for "..player.Name)
  74.     end
  75. end)
  76.  
  77. game.Players.PlayerRemoving:Connect(function(player)
  78.     local value = player.Lives.Value
  79.  
  80.     if value ~= nil then
  81.         print("Found data to save for "..player.Name.."!")
  82.         LivesSave:SetAsync(player.UserId, value)
  83.         print("Saved data for "..player.Name)
  84.     else
  85.         print("Did not manage to find data to save for "..player.Name.."!")
  86.     end
  87. end)
  88.  
  89. local CoinsSave = game:GetService("DataStoreService"):GetDataStore("Coins")
  90.  
  91. game.Players.PlayerAdded:Connect(function(player)
  92.     local previousData = CoinsSave:GetAsync(player.UserId) -- Returns a number value.
  93.  
  94.     local Coins
  95.  
  96.     if previousData ~= nil then
  97.         Coins = previousData
  98.     else
  99.         Coins = 0
  100.         CoinsSave:SetAsync(player.UserId, 0)
  101.     end
  102.  
  103.     if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIP) then
  104.         player.Coins.Value = player.Coins.Value * 2
  105.     end
  106. end)
  107.  
  108. game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
  109.     print("STOPPED!")
  110.  
  111.     for i,player in pairs(game.Players:GetPlayers()) do
  112.         local value = player.Coins.Value
  113.         CoinsSave:SetAsync(player.UserId, value)
  114.         print("Saved data for "..player.Name)
  115.     end
  116. end)
  117.  
  118. game.Players.PlayerRemoving:Connect(function(player)
  119.     local value = player.Coins.Value
  120.  
  121.     if value ~= nil then
  122.         print("Found data to save for "..player.Name.."!")
  123.         CoinsSave:SetAsync(player.UserId, value)
  124.         print("Saved data for "..player.Name)
  125.     else
  126.         print("Did not manage to find data to save for "..player.Name.."!")
  127.     end
  128. end)
  129.  
  130. local SaveRoles = game:GetService("DataStoreService"):GetDataStore("Role")
  131.  
  132. game.Players.PlayerAdded:Connect(function(player)
  133.  
  134.     local  Role = Instance.new("StringValue", player)
  135.     Role.Name = "Role"
  136.     Role.Value = player.Role.Value
  137.  
  138. end)
  139.  
  140. game:BindToClose(function()
  141.     for i,player in pairs(game.Players:GetPlayers()) do
  142.         local value = player.Role.Value
  143.         SaveRoles:SetAsync(player.UserId, value)
  144.         print("Saved data for "..player.Name)
  145.     end
  146. end)
  147.  
  148. game.Players.PlayerRemoving:Connect(function(player)
  149.     local value = player.Role.Value
  150.  
  151.     if value ~= nil then
  152.         print("Found data to save for "..player.Name.."!")
  153.         SaveRoles:SetAsync(player.UserId, value)
  154.         print("Saved data for "..player.Name)
  155.     else
  156.         print("Did not manage to find data to save for "..player.Name.."!")
  157.     end
  158. end)
  159.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement