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

How would I break this loop without it erroring?

So I just made this as an example, but the concept is the same.

How would I break this while loop without an error??

while true do
	if 2 > 1 then --Always True
		break
	end
	wait(1)
end

This concept is in my game script. The output says "end" expected near "if" at line [LINENUMBER], [LINENUMBER] being the line number of my if statement.

The problem is, there ARE enough ends. There are 2 ends; 1 for the if statement, 1 for the while loop. I will have to remake my entire game script if I can't find out a way. In the game script, the if statement is actually needed, and the break HAS to be inside of the if statement.

2 answers

What are you trying to accomplish here by breaking the while loop? I will need a bit more of your script to be able to understand the point of the while loop in the first place.

2 comments

0

Here is the script. The breaks are at line 220.

Use a variable instead of true. Once run is 'false', the while do statement will no longer be true and end the loop. You can return to the loop when run is set to 'true' again

local run = true

	while run do
	if 2 > 1 then -- Always true
		run = true -- When run is 'false' the loop will break
	end
end

3 comments

0

Thanks, but my while loop is actually being used for multiples of things, and I already used the while [CONDITION] setting. It is not while true do in my script.

0

You should have mentioned this in your question. Why didn't you do it?

0

You are also missing numerous information from your script. [LINENUMBER] doesn't help.

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