How do I terminate this function?

How do I disconnect functions such as GetMarkerReachedSignal with an argument?

For an example, I’d like GetMarkerReachedSignal on an animation to fire when the tool is equipped.

Tool.Equipped:Connect(function()
animation:GetMarkerReachedSignal("Test"):Connect(function()
print("hey")
end)
end)

Tool.Unequipped:Connect(function()
-- Disconnect the function?

Just a quick example:

local connection

connection = userinput.InputBegan:Connect(function()

end)

connection:Disconnect()

The Developer Hub has a good article about events, and disconnecting the signal. The example might help you implement it in your own code;

What it comes down to is that any :Connect() method returns a RBXScriptConnection which you can store in a variable. Calling :Disconnect() on this variable will then stop the event from triggering again.

local AnimationMarkerReachedConnection

Tool.Equipped:Connect(function()
	AnimationMarkerReachedConnection = animation:GetMarkerReachedSignal("Test"):Connect(function()
			print("hey")
	end)
end)

Tool.Unequipped:Connect(function()
	AnimationMarkerReachedConnection:Disconnect()	
end)
5 Likes

Ah my bad. Didn’t read your post correctly so it wasnt what you were looking for.