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

Loop wont break and i have no idea why. am i missing something about using break?

this is my basic script structure

local Module = {}



function Module.Function()
	
	local function LocalFunction()
		while true do
			wait(.1)
			if value is true then
				print("exp") -- this will print meaning the if condition was met but
				break -- this don't break
			end
			print("loop still running") -- this keeps printing after it should have broke
		end
	end

	LocalFunction()
end
	



return Module

1 comment

0

what is "value is"?

3 answers

✓ Accepted answer

Dude, it goes on forever because "while TRUEEEEEE do". Just put a boolean variable replacing true.

3 comments

0

Oh i thought if i broke out of the loop the thread would end and it wouldnt run again

0

did u check it though?

0

yes you were right i guess i just misunderstood how the while true do would react, thank you vary much

Huntergamind is 100% wrong, since you put "if value is<<(This does not exist) true then". It caused an error

It's "if value == true then"

while true do
	if value == true then
		print("exp")
		break
	end
end

1 comment

0

he was right its just in my exp i forgot to put two =s

Normally when using while loops I don't use breaks to stop them. I would use a variable in place of "true." Looking something like this(just copying your code and changing it)...

local Module = {}

function Module.Function()
	--removed the local function because you did not need it for what you had going
	while variable == false do--will run this loop until the variable is set to true
		--run code
         	wait(.1)
        end
end




return Module

As with your code, I am not sure what "value is" is referencing. When making variables they need to be one word. The break is never run in your code because the value is never set to true.

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