Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to put this function in a loop while keeping the others going?

Ok I have this function here that checks the amount of players on a team:

function getTeam(team)
    local players = game.Players:GetPlayers();
    local teamPlayers = {};
    for _, player in pairs(players) do
        if player.TeamColor == team.TeamColor then
            table.insert(teamPlayers, player);
        end
    end
    return teamPlayers;
end
	

And then I used it to start another function.

function waitforwinner()
if #getTeam(game.Teams.Survivors) == 0 then
		m = Instance.new("Message",Workspace)
			m.Text = "The final survivor was infected. Once you respawn the round will begin!"
		wait(3)
	m:Destroy()			
		for i,v in pairs(game.Players:GetPlayers()) do
			if v.TeamColor == BrickColor.new("Bright orange") then
			v.StarterGear.Revolver:remove()
		end
			v.Character.Humanoid.Health = 0
			wait(1)
			v.TeamColor = BrickColor.new("Bright blue")
			wait(5)			
		begin("The round has begun.",3)
		GiveGun()
		FirstInfected("A player has been randomly infected!",3)
		waitforwinner()
		waitForWinner()
		end
		end
end

The problem is that the getTeam function only checks once. So is there a way to make it so that function keeps checking so the second function will know when to work?

2 comments

0

Do not duplicate questions.

0

Can I get help with it. I know I shouldn't but how am I supposed to use this answer

1 answer

I dont believe you can run multiple functions at once on 1 script. This is because scripts read it how you would read it. Up and down. It cant split vision.

This discussion is preserved as it was. New answers, comments, and votes are closed.