Advertisement
Sungmingamerpro13

My Second Lobby DataStore (STORY GAME)

Nov 25th, 2024 (edited)
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 2.43 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2.  
  3. local VIP = 64418164
  4.  
  5. local LivesSave = game:GetService("DataStoreService"):GetDataStore("Lives")
  6.  
  7. game.Players.PlayerAdded:Connect(function(player)
  8.     local previousData = LivesSave:GetAsync(player.UserId) -- Returns a number value.
  9.  
  10.     local Lives
  11.  
  12.     if previousData ~= nil then
  13.         Lives = previousData
  14.     else
  15.         Lives = 0
  16.         LivesSave:SetAsync(player.UserId, 0)
  17.     end
  18.  
  19.     local LivesValue = Instance.new("IntValue", player)
  20.     LivesValue.Name = "Lives"
  21.     LivesValue.Value = Lives
  22.  
  23.     player.Lives.Value = 3
  24.    
  25. end)
  26.  
  27. game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
  28.     print("STOPPED!")
  29.  
  30.     for i,player in pairs(game.Players:GetPlayers()) do
  31.         local value = player.Lives.Value
  32.         LivesSave:SetAsync(player.UserId, value)
  33.         print("Saved data for "..player.Name)
  34.     end
  35. end)
  36.  
  37. game.Players.PlayerRemoving:Connect(function(player)
  38.     local value = player.Lives.Value
  39.  
  40.     if value ~= nil then
  41.         print("Found data to save for "..player.Name.."!")
  42.         LivesSave:SetAsync(player.UserId, value)
  43.         print("Saved data for "..player.Name)
  44.     else
  45.         print("Did not manage to find data to save for "..player.Name.."!")
  46.     end
  47. end)
  48.  
  49. local CoinsSave = game:GetService("DataStoreService"):GetDataStore("Coins")
  50.  
  51. game.Players.PlayerAdded:Connect(function(player)
  52.     local previousData = CoinsSave:GetAsync(player.UserId) -- Returns a number value.
  53.  
  54.     local Coins
  55.  
  56.     if previousData ~= nil then
  57.         Coins = previousData
  58.     else
  59.         Coins = 0
  60.         CoinsSave:SetAsync(player.UserId, 0)
  61.     end
  62.  
  63.     local coinsValue = Instance.new("IntValue", player)
  64.     coinsValue.Name = "Coins"
  65.     coinsValue.Value = Coins
  66.  
  67.     if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIP) then
  68.         player.Coins.Value = player.Coins.Value * 2
  69.     end
  70. end)
  71.  
  72. game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
  73.     print("STOPPED!")
  74.  
  75.     for i,player in pairs(game.Players:GetPlayers()) do
  76.         local value = player.Coins.Value
  77.         CoinsSave:SetAsync(player.UserId, value)
  78.         print("Saved data for "..player.Name)
  79.     end
  80. end)
  81.  
  82. game.Players.PlayerRemoving:Connect(function(player)
  83.     local value = player.Coins.Value
  84.  
  85.     if value ~= nil then
  86.         print("Found data to save for "..player.Name.."!")
  87.         CoinsSave:SetAsync(player.UserId, value)
  88.         print("Saved data for "..player.Name)
  89.     else
  90.         print("Did not manage to find data to save for "..player.Name.."!")
  91.     end
  92. end)
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement