For i loop doesnt work

I am making this intermission system, the for i loop only loops once and then stop (at 24) i dont know why this is happening.

The script is on a server script

function menu()
	for i = 25, 0, -1 do
		gameGUI.MenuFrame.TextLabel.Text =  "Next Round starting in "..tostring(i).." seconds..."
		task.wait(1)
	end

	fadeInLoading()
	local started = startMatch()
	if started == false then
		fadeOutLoading()
		menu()
	else
		startMatch()
	end
end

Context for the function? What happens before and after? It could happen that the script is destroyed.

Because the for do works:
image

here is the full function:

function menu()
	for i = 25, 0, -1 do
		gameGUI.MenuFrame.TextLabel.Text =  "Next Round starting in "..tostring(i).." seconds..."
		task.wait(1)
	end

	fadeInLoading()
	local started = startMatch()
	if started == false then
		fadeOutLoading()
		menu()
	else
		startMatch()
	end
end

When the timer reaches 0 (end of the loop) it is going to call the startMatch function, that returns a value. If the player counts is lower than 2, it restarts the timer. Else, it starts the match. However the timer stops at 24.

I dont think that the problem its outside of the function

The problem is outside of the loop

for i = 25, 0, -1 do 
   print(i)
end

Prints every number correctly.

UPD: actually the error is probably in here

So i added a print() and it actually prints but doesnt change the text. the code is on a server script

Do you see any errors? as they should be there. The function only prints 24 because it loops only once and then breaks because of the error in

gameGUI.MenuFrame.TextLabel.Text = "Next Round starting in "..tostring(i).." seconds..."

not at all. Changing gui should work in server scripts?

Wait you are doing it in a serverscript? No it won’t work…

So… how i change the gui to everyone at the same time? thats what i was trying to achieve

Use RemoteEvent:FireAllClients()

Fine i will try to use it ------

1 Like

Don’t forget to mark the solution if it works!

ill check the multiplayer, if it works ill check

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