So i have a script and inside the script is the entire games code. Inside the script i have a For Loop that counts down from 10 to 1. Once it hits 0 it SHOULD end the round. Well the part of the code that repeats until a certain thing changes (Such as the countdown hitting 0, the target dies, all players die etc) will not run until the for loop ends. I need this code BELOW the for loop to repeat while the for loop is running.
------------------------Variables------------------------------- minigames = game.Lighting.Minigames:GetChildren() -- Minigames Variable round = ("default") -- Round Status OfficerWep = game.Lighting.gun1 -- Officer Weapon HitmanWep = game.Lighting.gun2 -- Hitman Weapon message2 = game.Workspace.LobbyModel.Partmain.SurfaceGui.main -- The main GUI message3 = game.Workspace.LobbyModel.Partmain.SurfaceGui.timer -- The Timer GUI HitmanGUI = game.Lighting.HitmanGui OfficerGUI = game.Lighting.OfficerGui TimerGUI = game.Lighting.timeGui local sound = Instance.new("Sound") sound.SoundId = "http://www.roblox.com/asset/?id=130802245" sound.Parent = game.Workspace ------------------------Main------------------------------- function playMusic() sound:play() wait(10) end function checkPlayers() if game.Players.NumPlayers == 1 then repeat message2.Text = ("There needs to be more than 1 player to start") wait(1) until game.Players.NumPlayers == 2 end end while true do if game.Players.NumPlayers > 1 then if round == ("default") then --Checks if a round has recently ended print("Starting default round") --This will print the first time the server is started, i think. elseif round == ("over1") then message2.Text = ("Intermission: Next round will start in 10 seconds") wait(10) end sound:stop() checkPlayers() message2.Text = ("Randomly selecting map...") wait(3) ---------------Random select Map------------------------- checkPlayers() ranGame = math.random(1, #minigames) gameChosen = minigames[ranGame] checkPlayers() message2.Text = ("Map Chosen: " ..gameChosen.Name) wait(3) gameChosenClone = gameChosen:Clone() gameChosenClone.Parent = game.Workspace checkPlayers() message2.Text = ("Map Chosen: " ..gameChosen.Name) wait(3) message2.Text = ("Randomly selecting Hitman & Officer...") checkPlayers() wait(2) ---------------Random select hitman and officer---------- checkPlayers() Players = game.Players:GetPlayers() -- Add all players to Players table killer = Players[math.random(1,#Players)] -- Get a player, this player is defined under Players hero = Players[math.random(1,#Players)] ---------------Checking System---------- checkPlayers() if killer == hero then -- Checks if the selected killer/hero is the same, and if so changes it so its not repeat killer = Players[math.random(1,#Players)] wait(1) hero = Players[math.random(1,#Players)] until killer ~= hero print("The Hitman is " ..killer.Name) print("The Officer is " ..hero.Name) wait(1) end round = ("starting") ---------------Teleport players to selected map---------- spawns = gameChosenClone.Spawns:GetChildren() checkPlayers() message2.Text = ("Round in progress...") for i,v in pairs(game.Players:GetPlayers()) do name = v.Name check = game.Workspace:FindFirstChild(name) if check then checkHumanoid = check:FindFirstChild("Humanoid") if checkHumanoid then check:MoveTo(spawns[i].Position) end end end OfficerWep:Clone().Parent = hero.Backpack -- Gives the Officer Gun1 HitmanWep:Clone().Parent = killer.Backpack -- Gives the Hitman Gun2 --------------Tutorial GUI--------------------- OfficerGUI:Clone().Parent = hero.PlayerGui HitmanGUI:Clone().Parent = killer.PlayerGui wait(15) hero.PlayerGui.OfficerGui:Destroy() killer.PlayerGui.HitmanGui:Destroy() TimerGUI:Clone().Parent = killer.PlayerGui local killerGui = killer.PlayerGui.timeGui.TextLabel for i = 10, 0, -1 do killerGui.Text = "Time Left: " .. i message3.Text = "Time Left: " .. i wait(1) end --------------Round End--------------------- event = killer.Character.Humanoid.Died:connect(function() print("Killer has died!") for _, player in pairs(game.Players:GetPlayers()) do if player.Character then player.Character.Head:Destroy() round = ("over1") temphint = Instance.new("Hint", game.Workspace) temphint.Text = ("Citizens Win! :D") wait(4) killerGui:Destroy() Temphint:Destroy() end end event:disconnect() end) --------------Else--------------------- else playMusic() message2.Text = ("There needs to be more than 1 player to start") end wait(1) end