Class · inherits GuiObject
GuiButton
An abstract class for interactive 2D user interface elements.
About GuiButton
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
AutoButtonColor
: booleanDetermines whether the button automatically changes color when the mouse hovers over or clicks on it.This property determines whether the button automatically changes color when the user's
Mousehovers over or clicks on it. Iftrue, the button will automatically change color when the mouse hovers over or clicks on it. Iffalse, 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
ImageButtonand changing the element'sHoverImageandPressedImage.Please note that this property will not have an effect on an
ImageButtonif itsImageproperty is set to an image. Additionally, this property will not affect anImageButtonon mouse hover when itsHoverImageis notnil, nor on mouse click if itsPressedImageis notnil.HoverHapticEffect
: HapticEffectAHapticEffectinstance that will play when theGuiButtonis being hovered.A
HapticEffectthat 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 aHapticEffectto 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
HapticServicemixer, so whether the player actually feels vibration depends on their device and haptic settings. This property defaults tonil(no effect).Modal
: booleanIftruewhile the GUI element is visible, the mouse will not be locked unless the right mouse button is down.PressHapticEffect
: HapticEffectAHapticEffectinstance that will play when theGuiButtonis being pressed.A
HapticEffectthat the engine plays when the button enters its pressed state. Assign aHapticEffectto give press or click feedback; leave it unset for no press haptics.The effect plays through the standard
HapticServicemixer, so whether the player actually feels vibration depends on their device and haptic settings. This property defaults tonil(no effect).Selected
: booleanA boolean property which indicates whether the object has been selected.When set to
true, the button renders in a highlighted "selected" state instead of its normal idle appearance. This property defaults tofalse, and the engine never changes it automatically; set it yourself to mark a button as selected.Selectedonly has a visual effect on the legacyButtonStylepresets (theRoblox*styles) withAutoButtonColorenabled, where it swaps in the button's highlighted image. It has no effect under the defaultStyleofCustom. It is unrelated to gamepad and controller UI navigation; the currently focused element is tracked separately bySelectedObject.Style
: ButtonStyleSets the style of theGuiButtonbased on a list of pre-determined styles.Sets the button's overall appearance from a fixed set of
ButtonStylepresets. The default value isCustom, which applies no built-in styling and lets you control the button's appearance entirely through properties such asBackgroundColor3and, for anImageButton, its images.A legacy method of applying a fixed set of Roblox-themed button styles. The remaining presets (
RobloxButton,RobloxButtonDefault,RobloxRoundButton,RobloxRoundDefaultButton, andRobloxRoundDropdownButton) render Roblox-themed button art. New interfaces should keepCustomand style the button directly. This property defaults toButtonStyle.Custom.
Events 8
Activated
GuiButton.Activated:Connect(function(inputObject, clickCount))Fires when the button is activated.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,
clickCountwill start at0.As this event doesn't fire on the server, it should only be used in a
LocalScript, or in aScriptwithRunContextofRunContext.Client.MouseButton1Click
GuiButton.MouseButton1Click:Connect(function())Fires when the user's mouse fully left clicks theGuiButton.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
GuiButtonand the mouse button must be pressed down and up again before this event fires. If the mouse leaves the bounds of theGuiButtonand is released, the event will not fire. If you would like to avoid this limitation, you can useMouseButton1DownandMouseButton1Up; these events are similar but will fire whenever the user presses their left mouse button down or up, respectively.MouseButton1Down
GuiButton.MouseButton1Down:Connect(function(x, y))Fires when the user presses their left mouse button down on theGuiButton.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
GuiButtonin order for the event to fire, consider usingMouseButton1Click.MouseButton1Up
GuiButton.MouseButton1Up:Connect(function(x, y))Fires when the user releases their left mouse button off of theGuiButton.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
GuiButtonin order for the event to fire, consider usingMouseButton1Click.MouseButton2Click
GuiButton.MouseButton2Click:Connect(function())Fires when the user's mouse fully right clicks theGuiButton.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
GuiButtonand the mouse button must be pressed down and up again before this event fires. If the mouse leaves the bounds of theGuiButtonand is released, the event will not fire. If you would like to avoid this limitation, you can useMouseButton2DownandMouseButton2Up; these events are similar but will fire whenever the user presses their right mouse button down or up, respectively.MouseButton2Down
GuiButton.MouseButton2Down:Connect(function(x, y))Fires when the user presses their right mouse button down on theGuiButton.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
GuiButtonin order for the event to fire, consider usingMouseButton2Click.MouseButton2Up
GuiButton.MouseButton2Up:Connect(function(x, y))Fires when the user releases their right mouse button off of theGuiButton.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
GuiButtonin order for the event to fire, consider usingMouseButton2Click.SecondaryActivated
GuiButton.SecondaryActivated:Connect(function(inputObject))Fires when the button's "secondary" input is activated.Fires when a right-click press-and-release is detected from a mouse, long press is detected on a touch input,
R3is detected from a gamepad, or AltEnter is detected in UI navigation mode using keyboard.
GuiButton also has every member of GuiObject. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.