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

How to stop a function while its running?

Well, the title says it all. How to stop a function while its running??

Simple question, but is very vague, I know. Any help would be appreciated.

4 answers

You can just use a return statement. So if you had something like this then when a == 0 the function just ends:

local function demo(a)
	if a == 0 then
		return
	end
end

If you leave return without any values then it just returns nothing/0 but you can also return a value so you could do return 1 and if you did local b = demo(0) then b would equal 1.

Hope this helped!

Use return to break a function, this will end the function and allow you to return values to be used by other parts of your code. You can just use “break”, this will stop the loop.

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