Advertisement
Sungmingamerpro13

My New SaveData STORY GAME (Lobby)

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