Advertisement
Sungmingamerpro13

My New Leaderstats Lobby Story Game + Donation

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