Advertisement
Sungmingamerpro13

My New SaveData STORY GAME (Main)

Dec 2nd, 2023 (edited)
1,136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 3.52 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local AddRoundsDataStore = game:GetService("DataStoreService"):GetDataStore("AddRounds")
  3. local AddWinsDataStore = game:GetService("DataStoreService"):GetDataStore("AddWins")
  4. local SaveCurrency3 = game:GetService("DataStoreService"):GetDataStore("Coins")
  5. local SaveExtraLives = game:GetService("DataStoreService"):GetDataStore("Lives")
  6.  
  7. local VIPGamepassId = 64418164
  8.  
  9. game.Players.PlayerAdded:Connect(function(player)
  10.     if game.ReplicatedStorage.Tags.Leaderstats.Value == true then
  11.        
  12.         local AddRounds = Instance.new("NumberValue", player)
  13.         AddRounds.Name = "AddRounds"
  14.         AddRounds.Value = AddRoundsDataStore:GetAsync(player.UserId) or 0
  15.        
  16.         local AddWins = Instance.new("NumberValue", player)
  17.         AddWins.Name = "AddWins"
  18.         AddWins.Value = AddWinsDataStore:GetAsync(player.UserId) or 0
  19.  
  20.         local previousData = SaveCurrency3:GetAsync(player.UserId)
  21.         local Coins
  22.  
  23.         if previousData ~= nil then
  24.             Coins = previousData
  25.         else
  26.             Coins = 0
  27.             SaveCurrency3:SetAsync(player.UserId, 0)
  28.         end
  29.  
  30.         local CoinsValue = Instance.new("NumberValue", player)
  31.         CoinsValue.Name = "Coins"
  32.         CoinsValue.Value = Coins
  33.  
  34.         local val1 = Instance.new("StringValue",player)
  35.         val1.Name = 'GotPet'
  36.         val1.Value = ''
  37.  
  38.         local val2 = Instance.new("StringValue",player)
  39.         val2.Name = 'OpenValue'
  40.         val2.Value = ''
  41.  
  42.         local previousData2 = SaveExtraLives:GetAsync(player.UserId)
  43.         local Lives
  44.  
  45.         if previousData2 ~= nil then
  46.             Lives = previousData2
  47.         else
  48.             Lives = 0
  49.             SaveExtraLives:SetAsync(player.UserId, 0)
  50.         end
  51.  
  52.         local ExtraLivesValue = Instance.new("NumberValue", player)
  53.         ExtraLivesValue.Name = "Lives"
  54.         ExtraLivesValue.Value = Lives
  55.  
  56.         if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPGamepassId) then
  57.             player.Coins.Value = player.Coins.Value * 2
  58.         end
  59.        
  60.     end
  61. end)
  62.  
  63. game.Players.PlayerRemoving:Connect(function(player)
  64.     if game.ReplicatedStorage.Tags.Leaderstats.Value == true then
  65.         AddRoundsDataStore:SetAsync(player.UserId, player.AddRounds.Value)
  66.         AddWinsDataStore:SetAsync(player.UserId, player.AddWins.Value)
  67.     end
  68. end)
  69.  
  70. game:BindToClose(function()
  71.     print("STOPPED!")
  72.  
  73.     for i,player in pairs(game.Players:GetPlayers()) do
  74.         local value = player.Coins.Value
  75.         SaveCurrency3:SetAsync(player.UserId, value)
  76.         print("Saved data for "..player.Name)
  77.     end
  78. end)
  79.  
  80. game.Players.PlayerRemoving:Connect(function(player)
  81.     local value = player.Coins.Value
  82.  
  83.     if value ~= nil then
  84.         print("Found data to save for "..player.Name.."!")
  85.         SaveCurrency3:SetAsync(player.UserId, value)
  86.         print("Saved data for "..player.Name)
  87.     else
  88.         print("Did not manage to find data to save for "..player.Name.."!")
  89.     end
  90. end)
  91.  
  92. game:BindToClose(function()
  93.     print("STOPPED!")
  94.  
  95.     for i, player in pairs(game.Players:GetPlayers()) do
  96.         local value2 = player.Lives.Value
  97.         SaveExtraLives:SetAsync(player.UserId, value2)
  98.     end
  99. end)
  100.  
  101. game.Players.PlayerRemoving:Connect(function(player)
  102.     local value2 = player.Lives.Value
  103.  
  104.     if value2 ~= nil then
  105.         print("Found data to save for "..player.Name.."!")
  106.         SaveExtraLives:SetAsync(player.UserId, value2)
  107.         print("Saved data for "..player.Name)
  108.     else
  109.         print("Did not manage to find data to save for "..player.Name.."!")
  110.     end
  111. end)
  112.  
  113. game.Players.PlayerAdded:connect(function(player)
  114.     player.CharacterAdded:connect(function(char)
  115.  
  116.         char.Humanoid.Died:connect(function()
  117.             player.Lives.Value = player.Lives.Value - 1
  118.             player.AddRounds.Value = player.AddRounds.Value + 1
  119.         end)
  120.     end)
  121. end)
  122.  
  123.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement