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

Can you clear MouseButton1Click events from a button gui?

If i have a mouseclick event that was set on a certain button gui, but i want to write another mouseclick event to that same gui later on how can i erase the first connected event from triggering and only trigger the new one?

1 comment

0

You simply can't

1 answer

✓ Accepted answer

Yes, you can Disconnect connections to an RBXScriptConnection object that was created through a Connect().

local connection = button.MouseButton1Click:Connect(function()
	print("Before disconnecting.")
end)

wait(5) -- waits 5 seconds just for demonstration purposes

connection:Disconnect()

connection = button.MouseButton1Click:Connect(function()
	print("After disconnecting.")
end)

When you initially click, it will print "Before disconnecting." However, after 5 seconds, it will Disconnect() the MouseButtonClick connection, and the new Connect()'s function definition will make it print "After disconnecting."

2 comments

0

I like it.

0

Thanks brother big help

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