Advertisement
Sungmingamerpro13

My Second Main DataStore (STORY GAME)

Nov 25th, 2024 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 2.70 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2.  
  3. local VIP = 64418164
  4.  
  5. local DataStoreService = game:GetService("DataStoreService"):GetOrderedDataStore("Rounds")
  6.  
  7. local LivesSave = game:GetService("DataStoreService"):GetDataStore("Lives")
  8.  
  9. game.Players.PlayerAdded:Connect(function(player)
  10.     local previousData = LivesSave:GetAsync(player.UserId) -- Returns a number value.
  11.  
  12.     local Lives
  13.  
  14.     if previousData ~= nil then
  15.         Lives = previousData
  16.     else
  17.         Lives = 0
  18.         LivesSave:SetAsync(player.UserId, 0)
  19.     end
  20.  
  21.     local LivesValue = Instance.new("IntValue", player)
  22.     LivesValue.Name = "Lives"
  23.     LivesValue.Value = Lives
  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.  
  94. game.Players.PlayerAdded:Connect(function(player)
  95.     player.CharacterAdded:Connect(function(Char)
  96.  
  97.         Char.Humanoid.Died:Connect(function()
  98.             DataStoreService:IncrementAsync(player.UserId, 1)
  99.  
  100.         end)
  101.     end)
  102. end)
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement