Advertisement
Sungmingamerpro13

My New Leaderstats Lobby Story Game

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