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

Breaking functions run in other threads?

Will using break in a scope end any functions running in a separate thread under the same scope? If not, is there a way to do this efficiently? For instance,

i = 5

function Thingy()
	function FunctionInOtherThread()
		if i = 5 then
			for a = 1, 5 do
				print("i = 5")
				wait(10)
			end
		end
	end
	spawn(FunctionInOtherThread)
	repeat
		print("repeating til I break")
	until i == 6
	if i == 6 then break  --If I break here, will it end/stop/break FunctionInOtherThread(), in the other thread?
end

Like I wrote in the comment, would the FunctionInotherThread() break if I break Thingy()? Any help is appreciated, thanks!

P.S. I made that code up on the fly for an example, just saying. :)

1 answer

✓ Accepted answer

The simple answer is no. It also depends on how your code is. If there are other events in the function after your loop, it will continue and will not end. Break is designed to stop any loop in which it is located in. With this being the loop itself will stop, but the rest of the function will not. Also keep in mind that a function can be re-called so the loop can be broken as many times as the function is called with set conditions

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