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

How do i stop a function from running after it has been fired?

ive been having trouble with this for a while noww

1 answer

✓ Accepted answer

There are several ways to do this, but I'll outline two of the main methods this can be accomplished.

Debounces are more commonly used to stop functions from running after a certain goal has been met. Basically, you set a variable to a bool to either false or true (depending on what your prefer) and have the script check if the variable is true or not. If the condition is met, you then switch the bool so that the code can't run anymore. Here's an example:

local Debounce = false
part.Touched:connect(function(HitPart)
	if not Debounce then
		Debounce = true
		print("This brick was touched!!")
	end
end)

The :disconnect() method can be used to disconnect an event. I provided an example below.

	local Connection
	Connection = part.Touched:connect(function(hitpart)
		Connection:disconnect()
		print("This brick was touched!!")
	end)

1 comment

0

thanks dude, i never knew the disconnect method can be used in the variable

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