Advertisement
Sungmingamerpro13

My New Leaderstats Lobby (STORY GAME V7.10)

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