Class
GuiButton
NotCreatableNotBrowsable
An abstract class for interactive 2D user interface elements.
GuiButton is an abstract class that inherits from GuiObject.
It is the base class for the interactive, clickable ImageButton and
TextButton objects. This class also defines several properties for
interactive behavior, namely AutoButtonColor
and Modal.
The most important event of a GuiButton is
Activated, a multi-platform event that fires
when the button is activated. When using a mouse, this means clicking the
button and releasing with the cursor still over the UI object. For touch, the
same applies but with a touch instead of button press. Finally, for gamepads,
Activated fires if a GuiButton is selected
when the A button is pressed and released. In short, this event is very
useful for multi-platform user interface programming as it provides a nice
general interface for a single user input.
Properties 6#
AutoButtonColorboolean | Determines whether the button automatically changes color when the mouse hovers over or clicks on it.ReadSafe |
HoverHapticEffectHapticEffect | A HapticEffect instance that will play when the GuiButton
is being hovered.ReadSafe |
Modalboolean | If true while the GUI element is visible, the mouse will not be locked
unless the right mouse button is down.ReadSafe |
PressHapticEffectHapticEffect | A HapticEffect instance that will play when the GuiButton
is being pressed.ReadSafe |
Selectedboolean | A boolean property which indicates whether the object has been selected.ReadSafe |
StyleButtonStyle | Sets the style of the GuiButton based on a list of pre-determined
styles.ReadSafe |
AutoButtonColor: boolean#
ReadSafe
This property determines whether the button automatically changes color
when the user's Mouse hovers over or clicks on it. If true, the
button will automatically change color when the mouse hovers over or
clicks on it. If false, the button will not change.
If you would like to customize how a button changes when the user's mouse
hovers over or clicks on it, consider using an ImageButton and
changing the element's HoverImage and
PressedImage.
Please note that this property will not have an effect on an
ImageButton if its Image property is set
to an image. Additionally, this property will not affect an
ImageButton on mouse hover when its
HoverImage is not nil, nor on mouse click
if its PressedImage is not nil.
HoverHapticEffect: HapticEffect#
ReadSafe
A HapticEffect that the engine plays the first time the pointer
moves over the button, when the button transitions from its idle state to
its hover state. Assign a HapticEffect to give hover feedback (for
example, a light effect on gamepad or mobile); leave it unset for no hover
haptics.
The effect plays through the standard HapticService mixer, so
whether the player actually feels vibration depends on their device and
haptic settings. This property defaults to nil (no effect).
Modal: boolean#
ReadSafe
If true while the GUI element is visible, the mouse will not be locked
unless the right mouse button is down.
PressHapticEffect: HapticEffect#
ReadSafe
A HapticEffect that the engine plays when the button enters its
pressed state. Assign a HapticEffect to give press or click
feedback; leave it unset for no press haptics.
The effect plays through the standard HapticService mixer, so
whether the player actually feels vibration depends on their device and
haptic settings. This property defaults to nil (no effect).
Selected: boolean#
ReadSafe
When set to true, the button renders in a highlighted "selected" state
instead of its normal idle appearance. This property defaults to false,
and the engine never changes it automatically; set it yourself to mark a
button as selected.
Selected only has a visual effect on the legacy ButtonStyle
presets (the Roblox* styles) with
AutoButtonColor enabled, where it swaps
in the button's highlighted image. It has no effect under the default
Style of Custom. It is unrelated to gamepad and
controller UI navigation; the currently focused element is tracked
separately by SelectedObject.
Style: ButtonStyle#
ReadSafe
Sets the button's overall appearance from a fixed set of
ButtonStyle presets. The default value is Custom, which applies
no built-in styling and lets you control the button's appearance entirely
through properties such as
BackgroundColor3 and, for an
ImageButton, its images.
A legacy method of applying a fixed set of Roblox-themed button styles.
The remaining presets (RobloxButton, RobloxButtonDefault,
RobloxRoundButton, RobloxRoundDefaultButton, and
RobloxRoundDropdownButton) render Roblox-themed button art. New
interfaces should keep Custom and style the button directly. This
property defaults to ButtonStyle.Custom.
Events 8#
| Activated | Fires when the button is activated. |
| MouseButton1Click | Fires when the user's mouse fully left clicks the GuiButton. |
| MouseButton1Down | Fires when the user presses their left mouse button down on the
GuiButton. |
| MouseButton1Up | Fires when the user releases their left mouse button off of the
GuiButton. |
| MouseButton2Click | Fires when the user's mouse fully right clicks the GuiButton. |
| MouseButton2Down | Fires when the user presses their right mouse button down on the
GuiButton. |
| MouseButton2Up | Fires when the user releases their right mouse button off of the
GuiButton. |
| SecondaryActivated | Fires when the button's "secondary" input is activated. |
Activated(inputObject: InputObject, clickCount: int)#
Fires when a left click press-and-release is detected on desktop, touch
release is detected on mobile, or A/cross is activated in UI
navigation mode on console. The first time this method is called,
clickCount will start at 0.
As this event doesn't fire on the server, it should only be used in a
LocalScript, or in a Script with
RunContext of RunContext.Client.
| Name | Type | Default | Description |
|---|---|---|---|
inputObject | InputObject | An InputObject representing the user input that activated the
button. | |
clickCount | int | The number of consecutive rapid activations, starting at 0 for the first activation and incrementing with each subsequent activation within quick succession of the previous one. |
MouseButton1Click()#
This event fires when the user's mouse fully left clicks the
GuiButton.
In regards to clicking, the mouse must be in bounds of the
GuiButton and the mouse button must be pressed down and up again
before this event fires. If the mouse leaves the bounds of the
GuiButton and is released, the event will not fire. If you would
like to avoid this limitation, you can use
MouseButton1Down and
MouseButton1Up; these events are similar
but will fire whenever the user presses their left mouse button down or
up, respectively.
MouseButton1Down(x: int, y: int)#
This event fires when the user presses their left mouse button down on the
GuiButton.
For an event requiring the user to press and release their left mouse
on a GuiButton in order for the event to fire, consider using
MouseButton1Click.
| Name | Type | Default | Description |
|---|---|---|---|
x | int | The mouse's X screen coordinate in pixels. | |
y | int | The mouse's Y screen coordinate in pixels. |
MouseButton1Up(x: int, y: int)#
This event fires when the user releases their left mouse button off of the
GuiButton.
For an event requiring the user to press and release their left mouse
on a GuiButton in order for the event to fire, consider using
MouseButton1Click.
| Name | Type | Default | Description |
|---|---|---|---|
x | int | The mouse's X screen coordinate in pixels. | |
y | int | The mouse's Y screen coordinate in pixels. |
MouseButton2Click()#
This event fires when the user's mouse fully right clicks the
GuiButton.
In regards to clicking, the mouse must be in bounds of the
GuiButton and the mouse button must be pressed down and up again
before this event fires. If the mouse leaves the bounds of the
GuiButton and is released, the event will not fire. If you would
like to avoid this limitation, you can use
MouseButton2Down and
MouseButton2Up; these events are similar
but will fire whenever the user presses their right mouse button down or
up, respectively.
MouseButton2Down(x: int, y: int)#
This event fires when the user presses their right mouse button down on
the GuiButton.
For an event requiring the user to press and release their right mouse
on a GuiButton in order for the event to fire, consider using
MouseButton2Click.
| Name | Type | Default | Description |
|---|---|---|---|
x | int | The mouse's X screen coordinate in pixels. | |
y | int | The mouse's Y screen coordinate in pixels. |
MouseButton2Up(x: int, y: int)#
This event fires when the user releases their right mouse button off of
the GuiButton.
For an event requiring the user to press and release their right mouse
on a GuiButton in order for the event to fire, consider using
MouseButton2Click.
| Name | Type | Default | Description |
|---|---|---|---|
x | int | The mouse's X screen coordinate in pixels. | |
y | int | The mouse's Y screen coordinate in pixels. |
SecondaryActivated(inputObject: InputObject)#
Fires when a right-click press-and-release is detected from a mouse, long
press is detected on a touch input, R3 is detected from a gamepad, or
AltEnter is detected in UI navigation mode using
keyboard.
| Name | Type | Default | Description |
|---|---|---|---|
inputObject | InputObject | The input object representing the alternate activation action. |
Inherited members#
Inherited from GuiObject 51
Properties (30)
Active, AnchorPoint, AutomaticSize, BackgroundColor, BackgroundColor3, BackgroundTransparency, BorderColor, BorderColor3, BorderMode, BorderSizePixel, ClipsDescendants, Draggable, GuiState, InputSink, Interactable, LayoutOrder, NextSelectionDown, NextSelectionLeft, NextSelectionRight, NextSelectionUp, Position, Rotation, Selectable, SelectionImageObject, SelectionOrder, Size, SizeConstraint, Transparency, Visible, ZIndex
Methods (3)
Inherited from GuiBase2d 12
Properties (11)
AbsolutePosition, AbsoluteRotation, AbsoluteSize, AutoLocalize, Localize, RootLocalizationTable, SelectionBehaviorDown, SelectionBehaviorLeft, SelectionBehaviorRight, SelectionBehaviorUp, SelectionGroup
Events (1)
Inherited from Instance 58
Properties (10)
Archivable, archivable, Capabilities, IsInSandbox, Name, Parent, PredictionMode, RobloxLocked, Sandboxed, UniqueId
Methods (39)
AddTag, children, ClearAllChildren, Clone, clone, Destroy, destroy, FindFirstAncestor, FindFirstAncestorOfClass, FindFirstAncestorWhichIsA, FindFirstChild, findFirstChild, FindFirstChildOfClass, FindFirstChildWhichIsA, FindFirstDescendant, GetActor, GetAttribute, GetAttributeChangedSignal, GetAttributes, GetChildren, getChildren, GetDebugId, GetDescendants, GetFullName, GetStyled, GetStyledPropertyChangedSignal, GetTags, HasTag, IsAncestorOf, IsDescendantOf, isDescendantOf, IsPropertyModified, QueryDescendants, Remove, remove, RemoveTag, ResetPropertyToDefault, SetAttribute, WaitForChild