Advertisement
Sungmingamerpro13

My New Leaderboard STORY GAME + RolesSystem (LOBBY) (UPDATE)

Sep 30th, 2023 (edited)
1,661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 4.67 KB | Source Code | 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 SaveRoleData = game:GetService("DataStoreService"):GetDataStore("Role")
  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.         local previousData3 = SaveRoleData:GetAsync(player.UserId)
  49.         local Role
  50.  
  51.         if previousData2 ~= nil then
  52.             Lives = previousData2
  53.         else
  54.             Lives = 0
  55.             SaveExtraLives:SetAsync(player.UserId, 0)
  56.         end
  57.  
  58.         if previousData3 ~= nil then
  59.             Role = previousData3
  60.         else
  61.             Role = player.Role.Value
  62.             SaveRoleData:SetAsync(player.UserId, player.Role.Value)
  63.         end
  64.  
  65.         local ExtraLivesValue = Instance.new("NumberValue", player)
  66.         ExtraLivesValue.Name = "Lives"
  67.         ExtraLivesValue.Value = Lives
  68.        
  69.         local Role = Instance.new("StringValue", player)
  70.         Role.Name = "Role"
  71.         Role.Value = Role
  72.  
  73.         if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPGamepassId) then
  74.             player.Coins.Value = player.Coins.Value * 2
  75.         end
  76.  
  77.         player.Lives.Value = 5
  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 value2 = player.Role.Value
  136.         SaveRoleData:SetAsync(player.UserId, value2)
  137.     end
  138. end)
  139.  
  140. game.Players.PlayerRemoving:Connect(function(player)
  141.     local value2 = player.Role.Value
  142.  
  143.     if value2 ~= nil then
  144.         print("Found data to save for "..player.Name.."!")
  145.         SaveRoleData:SetAsync(player.UserId, value2)
  146.         print("Saved data for "..player.Name)
  147.     else
  148.         print("Did not manage to find data to save for "..player.Name.."!")
  149.     end
  150. end)
  151.  
  152. local teleportData = TeleportService:GetLocalPlayerTeleportData()
  153.  
  154. if teleportData then
  155.     local Player = game.Players:GetPlayerByUserId(teleportData.PlayerName)
  156.     Player.leaderstats.Wins.Value = Player.leaderstats.Wins.Value + 1
  157. end
  158.  
  159.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement