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

Is there a way to stop a function from running?

Is there a way to halt a function/prevent it from running? What I'm asking is something like this:

function a()
	print("start")
	wait(5)
	print("end")
end
-- Do something so it doesn't print "end"
...
-- Also if I do spawn or delay I would run later so...

4 comments

0

that depends on your use case, I'd use a simple variable, but then again, that might not be what you want/need

0

All I'm asking is a method so "end" doesn't print.

0

Use debounces

0

That would only fire once.

1 answer

To stop a function mid-process, you can use 'return'

Basically, it just tells the function to give some value back to whatever code ran it and automatically terminates the function just like 'end' does.

For example, in your case:

function a()
	print("start")
	a = "someValue"
	wait(5)
	if true then
		return a
	end
	print("end")
end
-- Do something so it doesn't print "end"
...
-- Also if I do spawn or delay I would run later so...

This would make the function return "someValue" to wherever you called it and end the function before printing "end"

2 comments

0

What if the value turns true right after the if statement passes? It would only fire once.

0

Then you'll have to design whatever it is you're programming with that in mind. You can always modify the if statement to have whatever criteria fits your particular circumstances. If you simply wish to wait until the value is true, change the if statement to a repeat x until y statement. The key here is the 'return' command in solving your problem of stopping the function early.

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