Advertisement
g14ndev

Escape the chasers main game loop

Mar 7th, 2024
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.39 KB | None | 0 0
  1. local intermission = game.Workspace.GameStatus.Intermission
  2. local roundLength = game.Workspace.GameStatus.RoundLength
  3. local Winner = game.Workspace.GameStatus.Winner
  4. local Started = game.Workspace.GameStatus.Started
  5. local Teams = game.Workspace:WaitForChild("TeamChecker")
  6. local Chasers = Teams.Chasers
  7. local Runners = Teams.Runners
  8. local runTel = workspace.RunnerTelPart
  9. local chaseTel = workspace.ChaserTelPart
  10. _G.chaserTable = {}
  11. _G.runnerTable = {}
  12.  
  13. local function gameOver ()
  14.     roundLength.Value = 0
  15. end
  16.  
  17.  
  18. while true do
  19.    
  20.    
  21.    
  22.     wait()
  23.    
  24.     local players = game:GetService("Players")
  25.     local playersTable = players:GetPlayers()
  26.  
  27.     local totalPlayers = #playersTable
  28.  
  29.     local maxChasers = math.floor(#playersTable / 3)
  30.    
  31.     if totalPlayers < 2 then continue end
  32.        
  33.    
  34.    
  35.  
  36.     if totalPlayers == 2 then
  37.         maxChasers = 1
  38.     end
  39.    
  40.    
  41.    
  42.     for i = intermission.Value, 0, -1 do
  43.         task.wait(1)
  44.         intermission.Value -= 1
  45.        
  46.     end
  47.    
  48.    
  49.  
  50.    
  51.    
  52.    
  53.    
  54.     for i, player in ipairs(playersTable) do
  55.         wait()
  56.         local random = math.random(1,2)
  57.         if math.floor(random) == 1 and player.Values.myTeam.Value == "Lobby" and totalPlayers > 2 then
  58.             print(player.Name.." is a Runner")
  59.             player.Values.myTeam.Value = "Runner"
  60.             Runners.Value = Runners.Value + 1
  61.             table.insert(_G.runnerTable, player)
  62.         end
  63.        
  64.         if math.floor(random) == 1 and player.Values.myTeam.Value == "Lobby" and totalPlayers == 2 and Runners.Value <= 0  then
  65.             print(player.Name.." is a Runner")
  66.             player.Values.myTeam.Value = "Runner"
  67.             Runners.Value = Runners.Value + 1
  68.             table.insert(_G.runnerTable, player)
  69.        
  70.         elseif math.floor(random) == 1 and player.Values.myTeam.Value == "Lobby" and totalPlayers == 2 and Runners.Value >= 1 then
  71.             print(player.Name.." is a Chaser")
  72.             player.Values.myTeam.Value = "Chaser"
  73.             Chasers.Value = Chasers.Value + 1
  74.             table.insert(_G.chaserTable, player)
  75.        
  76.         end
  77.         if math.floor(random) == 2 and Chasers.Value < maxChasers and player.Values.myTeam.Value == "Lobby" then
  78.             print(player.Name.." is a Chaser")
  79.             player.Values.myTeam.Value = "Chaser"
  80.             Chasers.Value = Chasers.Value + 1
  81.             table.insert(_G.chaserTable, player)
  82.         elseif math.floor(random) == 2 and Chasers.Value >= maxChasers and player.Values.myTeam.Value == "Lobby" then
  83.             print(player.Name.." is a Runner")
  84.             player.Values.myTeam.Value = "Runner"
  85.             Runners.Value = Runners.Value + 1
  86.             table.insert(_G.runnerTable, player)
  87.         end
  88.        
  89.         if player.Values.myTeam.Value == "Chaser" then
  90.             player.Character.HumanoidRootPart.Position = chaseTel.Position
  91.         end
  92.         if player.Values.myTeam.Value == "Runner" then
  93.             player.Character.HumanoidRootPart.Position = runTel.Position
  94.         end
  95.     end
  96.    
  97.    
  98.     Started.Value = true
  99.    
  100.    
  101.     repeat wait(1)
  102.         roundLength.Value -= 1
  103.         if #_G.chaserTable <= 0 then
  104.             gameOver()
  105.            
  106.         end
  107.         if #_G.runnerTable <=0 then
  108.             gameOver()
  109.         end
  110.        
  111.     until roundLength.Value <= 0
  112.    
  113.    
  114.     if #_G.runnerTable >= 1  then
  115.         print(#_G.runnerTable.." Runners survived")
  116.         Winner.Value = #_G.runnerTable.." RUNNERS WON!"
  117.     end
  118.     if #_G.runnerTable <= 0 then
  119.        
  120.         Winner.Value = "CHASERS WON!"
  121.        
  122.     end
  123.    
  124.     Started.Value = false
  125.    
  126.     for i, player in ipairs(playersTable) do
  127.        
  128.         if player.Values.myTeam.Value == "Runner" then
  129.             player.leaderstats.Wins.Value += 1
  130.             player.Values.Coins.Value += 10
  131.             player.Values.myTeam.Value = "Lobby"
  132.             Runners.Value = Runners.Value - 1
  133.             table.remove(_G.runnerTable, table.find(_G.runnerTable,player))
  134.         end
  135.         if player.Values.myTeam.Value == "Chaser" then
  136.             if #_G.runnerTable <= 0 then
  137.                 player.leaderstats.Wins.Value +=1
  138.                 player.Values.Coins.Value += 10
  139.                
  140.             end
  141.             player.Values.myTeam.Value = "Lobby"
  142.             Chasers.Value = Chasers.Value - 1
  143.             table.remove(_G.chaserTable, table.find(_G.chaserTable, player))
  144.         end
  145.         player.Backpack:ClearAllChildren()
  146.         player.Values.HasTool.Value = false
  147.         player.Character.Humanoid.Health = 0
  148.     end
  149.    
  150.     players.PlayerRemoving:Connect(function(plr)
  151.         local wasRunner = table.find(_G.runnerTable, plr )
  152.         local wasChaser = table.find(_G.chaserTable, plr)
  153.        
  154.         if wasRunner then
  155.             table.remove(_G.runnerTable, wasRunner)
  156.             Runners.Value = Runners.Value - 1
  157.         end
  158.         if wasChaser then
  159.             table.remove(_G.chaserTable, wasChaser)
  160.             Chasers.Value = Chasers.Value - 1
  161.         end
  162.     end)
  163.    
  164.    
  165.    
  166.     Runners.Value = 0
  167.     Chasers.Value = 0
  168.    
  169.    
  170.     wait(5)
  171.     intermission.Value = 10
  172.     roundLength.Value = 120
  173.    
  174.    
  175.    
  176.    
  177.    
  178. end
Tags: Roblox lua
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement