Advertisement
Sungmingamerpro13

My New Leaderboard STORY GAME (Lobby)

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