Repeat function not working properly?

Basically, I have a script that adds rounds into my game.

Script:

while true do
	-- Intermission before the round starts
	intermission(INTERMISSION_TIME) -- teleports players to lobby and waits INTERMISSION_TIME
	print("Round starting!")
	

	start() -- teleports players to map

	
	repeat
		wait(1)
	until #game.Teams.Humans:GetPlayers() == 0 --wait until every player is on the zombie team
	--wait until 0 humans are left, then repeat the loop
end

It’s not picking up when 0 humans are left.

I dont often use the repeat command, so i might not be much help but i can try give a go

Just want to double check; you have made sure that the players are always going to the correct team? You are also using the right team?

Try putting a print statement in the repeat function to make sure it is actually functioning. Let me know what happens.

You could also try separate functions, and do a while loop for the start function and for the wait until no players left. you could try a while #game.Teams.Humans:GetPlayers() > 0 do

I suggest adding the following debug print:

...
	repeat print(#game.Teams.Humans:GetPlayers(), "players left.")
		task.wait(1) --//Please use task library functions
	until #game.Teams.Humans:GetPlayers() == 0 --wait until every player is on the zombie team
	--wait until 0 humans are left, then repeat the loop
end
2 Likes

It for some reason keeps printing that 1 player is left after switching. (I’m changing teams on the serverside)

Okay, there you have it. Something is going wrong in your script that handles changing teams after dying/losing. Either look further into it yourself or share the script that handles said functions.

I’m typing it in the command bar. It makes me switch teams and there is no error. It might lie in the script itself

command bar (when play testing first) is on the client side, you need to switch to the server and then type there the command

1 Like

If you manually change your team to ‘Zombies’ and it continues without errors, then the script works.
If you want the game to change your team to ‘Zombies’ and the script still keeps repeating, then the fault lies in the script that handles the player’s team change. If you need further assistance, we need to see the script/portion that handles the player teams.

Thanks. Is there any way to make the command bar server side?

In The Home Tab (when you playtest) there should be a button with Current: Client at the top somewhere click on it and you will change to client