How would I stop a function from outside of that function?

I have a function that makes the slide on my gun go back and I want to stop that function and some other functions if the tool is unequipped but I’m not sure how I would go about it

basically just

Tool.Unequipped:Connect(function()
            i want to stop the function here.
	Equipped = false
	cdown = false
end)

https://developer.roblox.com/en-us/api-reference/lua-docs/coroutine

but coroutines can only be yielded inside them right?

local toStop = Tool.Unequipped:Connect(function()
	Equipped = false
	cdown = false
end)

wait(5)
toStop:Disconnect()

thats not what i meant, i meant theres another function and i want to stop that function when the player unequips the tool.

you could put the Unequipped signal inside the function and then just do “return” or you could have a bool value, and set it to true when the Unequipped signal fires. Then the function sees that and stops.

I do recommend disconnecting the signal after it has fired tho else it will run every time the tool gets unequipped even when the function has stopped.

dont know how i didnt think of this! i will try now.

1 Like