How do I stop this function from running anymore?

So as you see this is a function

		obj.Touched:Connect(function(hitObj) -- if obj is hit. light HitObj on fire
			if effectThere then -- check if its the right material. Or a humanoid

				if hitObj.Parent:FindFirstChild('Humanoid') then
					
					flameObject(hitObj)
				elseif materials:FindFirstChild(hitObj.Material.Name) then
					flameObject(hitObj)
				end
			else
				print('STOP THE FUNCTION') -- I want to stop the function here
			end
		end)

Anyhow if a certain value is not met I want this function to stop running for this script. Cause then every time the obj touches something this will trigger.

Cool thanks

You could change this to:

local Connection
Connection = obj.touched:Connect(function(hitObj)
-- Your code
end)

Then when you wanna disconnect it simply do this:

Connection:Disconnect()

And yes I know you want it to stop forever, I don’t have much time rn so this is all I can write.

1 Like

When the condition is met just use the return keyword and it will terminate the function and return to where it was called.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.