Problem with repeat function

I want my countdown to do 15 to 0

The issue is that the countdown dont stop at 0 and continue to -1, -2, -3 ext…
The script :

local function intermissionTimer()
	LobbyCount.Text = intermissionLength
	
	repeat
		LobbyCount.Text = LobbyCount.Text - 1
		wait(1)
	until LobbyCount.Text == 0
end

I tried to do While wait(1) do and placed and if then to when break the loop but still dont work, and i cant find my problem on the Hub.

local count = 15

local function intermissionTimer()
  count = 15
  while count >0 do
    count = count - 1
    LobbyCount.Text = count
    wait(1)
  end
  --Other code after while loop,
--e.g. LobbyCount.Text = "Timer done!"
end

This resets the timer each time

1 Like

You could just use a for loop for example:

local count = 15 

local function intermissionTimer()
      for i = count, 0, -1 do
           wait(1)
           LobbyCount.Text = i
      end
end

This way you can ensure that it always goes to the end value, which would be the second number when formatting the for loop that’s why i set it to zero. Also, remember that when making a count-down to make the increment, the third number when formatting a for loop, be a negative number. And usually make it a negative one because I’m assuming you would want the count-down to go down by each individual second.

Hopefully, this helps.
Have a wonderful day.

1 Like