> For the complete documentation index, see [llms.txt](https://docs.overdare.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.overdare.com/development/api-reference/classes/guibutton.md).

# GuiButton

GuiButton : `GuiObject`

## Overview

GuiButton is an abstract class that inherits from GuiObject, defining shared functionality for clickable UI elements like TextButton and ImageButton

## Properties

### AutoButtonColor

`boolean`

Specifies whether to automatically darken the background color when the mouse hovers over or presses the button, to indicate the input state.

The default is true. If you want to create the button's color changes directly with a script, setting it to false is recommended.

#### Code Samples

```lua
local ScreenGui = script.Parent
local TextButton = ScreenGui:WaitForChild("TextButton")

TextButton.AutoButtonColor = false
```

### Modal

`boolean`

Specifies whether to display the mouse cursor.

#### Code Samples

```lua
local ScreenGui = script.Parent
local TextButton = ScreenGui:WaitForChild("TextButton")

TextButton.Modal = true
```

### Selected

`boolean`

Specifies the selection state of the button.

If set to true, the button receives keyboard focus, and if set to false, the focus is released.

#### Code Samples

```lua
local ScreenGui = script.Parent
local TextButton = ScreenGui:WaitForChild("TextButton")

TextButton.Selected = true
```

### Style

`Enum.ButtonStyle`

Specifies the basic shape to apply to the button.

The default, Custom, uses the button's background properties as they are. Other values apply a predefined corner shape, and values starting with Round display rounded corners.

#### Code Samples

```lua
local ScreenGui = script.Parent
local TextButton = ScreenGui:WaitForChild("TextButton")

TextButton.Style = Enum.ButtonStyle.RoundButton
```

## Methods

## Events

### Activated

The event triggers when the button is pressed.

It fires when a button is clicked or touched and released over the UI element, executing at the input’s release (Up) rather than its start.

For this event to fire correctly, the button’s Active property must be set to true.

#### Parameters

| `InputObject` inputObject | The InputObject corresponding to the input that activated the button. nil is passed if the input information cannot be determined. |
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `number` clickCount       | The number of clicks. Currently, 1 is always passed.                                                                               |

#### Code Samples

```lua
local ScreenGui = script.Parent
local ImageButton = ScreenGui.ImageButton

local function OnActivated()
    print("Activated!")
end
ImageButton.Activated:Connect(OnActivated)
```

### MouseButton1Click

An event that fires when the button is pressed with the left mouse button (or touch) and released over the button.

It fires right before the Activated event. To support multiple input devices together, using the Activated event is recommended.

#### Parameters

#### Code Samples

```lua
local ScreenGui = script.Parent
local TextButton = ScreenGui:WaitForChild("TextButton")

local function OnMouseButton1Click()
    print("MouseButton1Click")
end
TextButton.MouseButton1Click:Connect(OnMouseButton1Click)
```

### MouseButton1Down

An event that fires the moment the button is pressed with the left mouse button (or touch).

#### Parameters

| `number` x | The X coordinate (in pixels) on screen where the input occurred. |
| ---------- | ---------------------------------------------------------------- |
| `number` y | The Y coordinate (in pixels) on screen where the input occurred. |

#### Code Samples

```lua
local ScreenGui = script.Parent
local TextButton = ScreenGui:WaitForChild("TextButton")

local function OnMouseButton1Down(x, y)
    print("MouseButton1Down : ", x, y)
end
TextButton.MouseButton1Down:Connect(OnMouseButton1Down)
```

### MouseButton1Up

An event that fires the moment the left mouse button (or touch) that was pressing the button is released.

#### Parameters

| `number` x | The X coordinate (in pixels) on screen where the input occurred. |
| ---------- | ---------------------------------------------------------------- |
| `number` y | The Y coordinate (in pixels) on screen where the input occurred. |

#### Code Samples

```lua
local ScreenGui = script.Parent
local TextButton = ScreenGui:WaitForChild("TextButton")

local function OnMouseButton1Up(x, y)
    print("MouseButton1Up : ", x, y)
end
TextButton.MouseButton1Up:Connect(OnMouseButton1Up)
```

### MouseButton2Click

An event that fires when the button is pressed with the right mouse button and released over the button.

#### Parameters

#### Code Samples

```lua
local ScreenGui = script.Parent
local TextButton = ScreenGui:WaitForChild("TextButton")

local function OnMouseButton2Click()
    print("MouseButton2Click")
end
TextButton.MouseButton2Click:Connect(OnMouseButton2Click)
```

### MouseButton2Down

An event that fires the moment the button is pressed with the right mouse button.

#### Parameters

| `number` x | The X coordinate (in pixels) on screen where the input occurred. |
| ---------- | ---------------------------------------------------------------- |
| `number` y | The Y coordinate (in pixels) on screen where the input occurred. |

#### Code Samples

```lua
local ScreenGui = script.Parent
local TextButton = ScreenGui:WaitForChild("TextButton")

local function OnMouseButton2Down(x, y)
    print("MouseButton2Down : ", x, y)
end
TextButton.MouseButton2Down:Connect(OnMouseButton2Down)
```

### MouseButton2Up

An event that fires the moment the right mouse button that was pressing the button is released.

#### Parameters

| `number` x | The X coordinate (in pixels) on screen where the input occurred. |
| ---------- | ---------------------------------------------------------------- |
| `number` y | The Y coordinate (in pixels) on screen where the input occurred. |

#### Code Samples

```lua
local ScreenGui = script.Parent
local TextButton = ScreenGui:WaitForChild("TextButton")

local function OnMouseButton2Up(x, y)
    print("MouseButton2Up : ", x, y)
end
TextButton.MouseButton2Up:Connect(OnMouseButton2Up)
```

### SecondaryActivated

An event that fires when a secondary action input on the button is completed.

With a mouse, it fires right after the MouseButton2Click event when the button is pressed and released with the right mouse button.

#### Parameters

| `InputObject` inputObject | An object containing information about the input that fired the event. |
| ------------------------- | ---------------------------------------------------------------------- |

#### Code Samples

```lua
local ScreenGui = script.Parent
local TextButton = ScreenGui:WaitForChild("TextButton")

local function OnSecondaryActivated(inputObject)
    print("SecondaryActivated : ", inputObject.UserInputType)
end
TextButton.SecondaryActivated:Connect(OnSecondaryActivated)
```
