PcoWSkbVqDnWTu_dm2ix
The Developer Hub is now deprecated and information on this page may no longer be accurate. To see our new and improved documentation, please click here. You can read more about the future of documentation here.
Collapse Sidebar

MouseButton1Click

The MouseButton1Click event fires when the user’s Mouse fully left clicks the GUI button.

By clicking, the mouse has to be in bounds of the button and has to be pressed down and up again before this event fires. If the mouse leaves the bounds of the button and is released, the even will not fire. If you would like to avoid this limitation, you can use GuiButton/MouseButton1Down and MouseButton1Up. These events are similar, but will fire whenever the user pressed their left mouse down or up, respectively.

This event is similar to GuiButton/MouseButton2Click, which behaves identically except that it is connected to the user’s right mouse button.

Note that this event will only fire for GUI buttons, including TextButton|TextButtons and ImageButton|ImageButton. It will not fire for other GuiObject|GuiObjects.


Code Samples


Handling User Clicks on a GUI Button

The code sample below demonstrates how to use the GuiButton/MouseButton1Click and GuiButton/MouseButton2Click events to handle user left and right mouse button input on a GuiButton.

For the example to work expected, the LocalScript containing the code should be a child of the GUI button.