'else' function only triggers once

so im making an intermission script and when there’s not enough players the countdown stops is what im trying to do but the else function triggers only once and when the enoughPlayers changes back to false again it will not print it back but instead do the function it was doing when the bool was set to true

local function countdownTimer()
	while wait() do
		if enoughPlayers.Value == true then
			for i = intermissionLength, 1, -1 do
				ingame.Value = false
				wait(1)
				timer.Value = i
			end
			
			for i = gameLength, 1, -1 do
				ingame.Value = true
				wait(1)
				timer.Value = i
			end
		else
			print("not enough players")
			--some stuff here
		end
	end
end

spawn(countdownTimer)

The code looks fine. But when a game has started, it doesn’t repeat the while loop (and therefore doesn’t check the if statement the else is on) until the intermission and game time have passed.

To fix it, either before or after every wait() you need to check the value and if the value is false then have it break the loop or something to return it back to the outer loop.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.