Class · inherits GuiBase2d
GuiObject
An abstract class for all 2D user interface objects.
About GuiObject
GuiObject is an abstract class (much like BasePart) for a 2D
user interface object. It defines all the properties relating to the display
of a graphical user interface (GUI) object such as Size
and Position. It also has some useful read‑only
properties like AbsolutePosition,
AbsoluteSize, and
AbsoluteRotation.
To manipulate the layout of GUI objects in special ways, you can use a layout structure such as list/flex or grid, and you can style them beyond their core properties through appearance modifiers.
Although it's possible to detect mouse button events on any GUI object using
InputBegan and
InputEnded, only ImageButton and
TextButton have convenient dedicated events such as
Activated to detect click/press.
Properties 26
Active
: booleanDetermines whether this UI element sinks input.This property determines whether the
GuiObjectwill sink input to 3D space, such as underlying models with aClickDetectorclass likeDragDetector.For
GuiButtonobjects (ImageButtonandTextButton), this property determines whetherActivatedfires (AutoButtonColorwill still work for those as well). The eventsInputBegan,InputChanged, andInputEndedwork as normal no matter the value of this property.AnchorPoint
: Vector2Determines the origin point of aGuiObject, relative to its absolute size.This property determines the origin point of a
GuiObject, relative to its absolute size. The origin point determines from where the element is positioned (throughGuiObject.Position) and from which the renderedGuiObject.Sizeexpands.See here for illustrated diagrams and details.
AutomaticSize
: AutomaticSizeDetermines whether resizing occurs based on child content.This property is used to automatically size parent UI objects based on the size of its descendants. You can use this property to dynamically add text and other content to a UI object at edit or run time, and the size will adjust to fit that content.
When
AutomaticSizeis set to anAutomaticSizevalue to anything other thanNone, this UI object may resize depending on its child content.For more information on how to use this property and how it works, please see here.
BackgroundColor3
: Color3Determines theGuiObjectbackground color.This property determines the color of a
GuiObjectbackground (the fill color). If your element contains text, such as aTextBox,TextButton, orTextLabel, make sure the color of your background contrasts the text's color.Another property that determines the visual properties of the background is
GuiObject.BackgroundTransparency; if this is set to1, neither the background nor the border will render.See also
BorderColor3.BackgroundTransparency
: floatDetermines the transparency of theGuiObjectbackground and border.This property determines the transparency of the
GuiObjectbackground and border. It does not, however, determine the transparency of text if the GUI is aTextBox,TextButton, orTextLabel; text transparency is determinedTextBox.TextTransparency,TextButton.TextTransparency, andTextLabel.TextTransparencyrespectively.If this property is set to
1, neither the background nor the border will render and the GUI background will be completely transparent.BorderColor3
: Color3Determines the color of theGuiObjectborder.Determines the color of the
GuiObjectrectangular border (also known as the stroke color). This is separate from the object'sGuiObject.BackgroundColor3. You will not be able to see the object's border if itsGuiObject.BorderSizePixelproperty is set to0.Note that the
UIStrokecomponent allows for more advanced border effects.BorderMode
: BorderModeDetermines in what manner theGuiObjectborder is laid out relative to its dimensions.This property determines in what manner the
GuiObjectborder is laid out relative to its dimensions using the enum of the same name,BorderMode.Note that
UIStrokecan override this property and allow for more advanced border effects.ClipsDescendants
: booleanDetermines if descendantGuiObjectsoutside of the bounds of a parent GUI element should render.This property determines if the
GuiObjectwill clip (make invisible) any portion of descendant GUI elements that would otherwise render outside the bounds of the rectangle.Rotation Behavior
When
StarterGui.ClipsDescendantsSupportsRotationis enabled, clipping works correctly for rotated shapes. However, clipping by rotated shapes (when the clipping parent itself is rotated) or by rounded corners (UICorner) is not supported.When
StarterGui.ClipsDescendantsSupportsRotationis not enabled and thisGuiObjector any ancestorGuiObjecthas a non‑zeroRotation, this property is ignored and descendant GUI elements will render regardless of this property's value.GuiState
: GuiStateReadOnlyNotReplicatedDetermines whether the player's mouse is being actively pressed on theGuiObjector not.When the player's finger is being tapped and held on the
GuiObject, theGuiStateof theGuiObjectwill be set toPress. Similarly, When the player's finger is being released from theGuiObject, theGuiStateof theGuiObjectwill be set toIdle, and whenInteractableis turned off on theGuiObject, theGuiStateof theGuiObjectwill be set toNonInteractable.InputSink
: InputSinkNotReplicatedControls whether, and how, theGuiObjectsinks input that occurs over it.Controls whether, and to what degree, the
GuiObjectsinks input that occurs over it, usingInputSink. Sinking input prevents it from passing through to objects behind the element, including 3D objects in the world such as those with aClickDetectororDragDetector. It defaults toInputSink.None, except onGuiButtonobjects (ImageButtonandTextButton), where it defaults toInputSink.Activate.InputSink.None— the object does not sink input on its own.InputSink.Activate— the object sinks the mouse-button and touch press/release input used to activate it, but lets other input (such as mouse movement) pass through.InputSink.All— the object sinks all input that occurs over it.
This property is a more granular successor to the boolean
Activeproperty, which can only sink all input or none. TheInputBegan,InputChanged, andInputEndedevents fire regardless of this property's value.Interactable
: booleanDetermines whether theGuiButtoncan be interacted with or not, or if theGuiStateof theGuiObjectis changing or not.Determines whether the
GuiButtoncan be interacted with or not, or if theGuiStateof theGuiObjectis changing or not.On a
GuiButton:- When the
Interactablesetting on theGuiButtonis set tofalse, theGuiButtonwill no longer be able to be pressed or clicked, and theGuiStatewill be constantly set toNonInteractable. - When the
Interactablesetting on theGuiButtonis set totrue, theGuiButtonwill behave normally again and theGuiStatewill behave normally.
On a
GuiObject:- When the
Interactablesetting on theGuiButtonis set tofalse, theGuiStatewill be constantly set toNonInteractable. - When the
Interactablesetting on theGuiButtonis set totrue, theGuiStatewill behave normally again.
- When the
LayoutOrder
: intControls the sort order of theGuiObjectwhen used with aUIGridStyleLayout.This property controls the sorting order of the
GuiObjectwhen using aUIGridStyleLayout(such asUIListLayoutorUIPageLayout) withSortOrderset toSortOrder.LayoutOrder. It has no functionality if the object does not have a sibling UI layout structure.GuiObjectsare sorted in ascending order where lower values take priority over higher values. Objects with equal values fall back to the order they were added in.If you are unsure if you'll need to add an element between two existing elements in the future, it's a good practice to use multiples of
100(0,100,200, etc.). This ensures a large gap of layout order values which you can use for elements ordered in-between other elements.See also
ZIndexwhich determines the object's rendering order instead of sorting order.NextSelectionDown
: GuiObjectSets theGuiObjectwhich will be selected when the gamepad selector is moved downward.This property sets the
GuiObjectselected when the user moves the gamepad selector downward. If this property is empty, moving the gamepad downward will not change the selected GUI.Moving the gamepad selector downward sets the
GuiService.SelectedObjectto this object unless the GUI is notSelectable. Note that this property can be set to a GUI element even if it is notSelectable, so you should ensure that the value of a GUI's selectable property matches your expected behavior.See also
NextSelectionUp,NextSelectionLeft, andNextSelectionRight.NextSelectionLeft
: GuiObjectSets theGuiObjectwhich will be selected when the gamepad selector is moved to the left.This property sets the
GuiObjectselected when the user moves the gamepad selector to the left. If this property is empty, moving the gamepad to the left will not change the selected GUI.Moving the gamepad selector to the left sets the
GuiService.SelectedObjectto this object unless the GUI is notSelectable. Note that this property can be set to a GUI element even if it is notSelectable, so you should ensure that the value of a GUI's selectable property matches your expected behavior.See also
NextSelectionUp,NextSelectionDown, andNextSelectionRight.NextSelectionRight
: GuiObjectSets theGuiObjectwhich will be selected when the gamepad selector is moved to the right.This property sets the
GuiObjectselected when the user moves the gamepad selector to the right. If this property is empty, moving the gamepad to the right will not change the selected GUI.Moving the gamepad selector to the right sets the
GuiService.SelectedObjectto this object unless the GUI is notSelectable. Note that this property can be set to a GUI element even if it is notSelectable, so you should ensure that the value of a GUI's selectable property matches your expected behavior.See also
NextSelectionUp,NextSelectionDown, andNextSelectionLeft.NextSelectionUp
: GuiObjectSets theGuiObjectwhich will be selected when the gamepad selector is moved upward.This property sets the
GuiObjectselected when the user moves the gamepad selector upward. If this property is empty, moving the gamepad upward will not change the selected GUI.Moving the gamepad selector upward sets the
GuiService.SelectedObjectto this object unless the GUI is notSelectable. Note that this property can be set to a GUI element even if it is notSelectable, so you should ensure that the value of a GUI's selectable property matches your expected behavior.See also
NextSelectionDown,NextSelectionLeft,NextSelectionRight.Position
: UDim2Determines the pixel and scalar position of theGuiObject.This property determines the
GuiObjectpixel and scalar position using aUDim2. Position is centered around the object'sGuiObject.AnchorPoint.The scalar position is relative to the size of the parent GUI element, if any.
The pixel portions of the
UDim2value are the same regardless of the parent GUI's size. The values represent the position of the object in pixels. An object's actual pixel position can be read from theGuiBase2d.AbsolutePositionproperty.Rotation
: floatDetermines the number of degrees by which theGuiObjectis rotated.This property determines the number of degrees by which the
GuiObjectis rotated. Rotation is relative to the center of the object, not theAnchorPoint, meaning you cannot change the point of rotation. Additionally, this property is not compatible withClipsDescendants.Selectable
: booleanDetermine whether theGuiObjectcan be selected by a gamepad.This property determines whether the
GuiObjectcan be selected when navigating GUIs using a gamepad.If this property is
true, a GUI can be selected. Selecting a GUI also sets theGuiService.SelectedObjectproperty to that object.When this is
false, the GUI cannot be selected. However, setting this tofalsewhen a GUI is selected will not deselect it nor change the value of theGuiService.SelectedObjectproperty.Add
GuiObject.SelectionGainedandGuiObject.SelectionLostwill not fire for the element. To deselect a GuiObject, you must change theGuiService.SelectedObjectproperty.This property is useful if a GUI is connected to several GUIs via properties such as this
GuiObject.NextSelectionUp,GuiObject.NextSelectionDown,NextSelectionRight, orNextSelectionLeft. Rather than change all of the properties so that the Gamepad cannot select the GUI, you can disable its Selectable property to temporarily prevent it from being selected. Then, when you want the gamepad selector to be able to select the GUI, simply re-enable its selectable property.SelectionImageObject
: GuiObjectOverrides the default selection adornment used for gamepads.This property overrides the default selection adornment used for gamepads.
Note that the chosen
SelectionImageObjectoverlays the selectedGuiObjectwith theSizeof the image. For best results, you should size the customSelectionImageObjectvia the scaleUDim2values to help ensure that the object scales properly over the selected element.Changing the
SelectionImageObjectfor aGuiObjectelement only affects that element. To affect all of a user's GUI elements, set thePlayerGui.SelectionImageObjectproperty.To determine or set which GUI element is selected by the user, you can use the
GuiService.SelectedObjectproperty. The player uses the gamepad to select different GUI elements, invoking theNextSelectionUp,NextSelectionDown,NextSelectionLeft, andNextSelectionRightevents.SelectionOrder
: intThe order ofGuiObjectsselected by the gamepad UI selection.GuiObjects with a lower SelectionOrder are selected earlier than GuiObjects with a higher SelectionOrder when starting the gamepad selection or calling
GuiService.Selecton an ancestor. This property does not affect directional navigation. Default value is 0.Size
: UDim2Determines the pixel and scalar size of theGuiObject.This property determines the
GuiObjectscalar and pixel size using aUDim2.The scalar size is relative to the size of the parent GUI element, if any.
The pixel portions of the
UDim2value are the same regardless of the parent GUI's size. The values represent the size of the object in pixels. An object's actual pixel size can be read from theGuiBase2d.AbsoluteSizeproperty.If the
GuiObjecthas a parent, its size along each axis is also influenced by the parent'sSizeConstraint.Visible
: booleanDetermines whether theGuiObjectand its descendants will be rendered.This property whether the
GuiObjectand its descendants will be rendered.The rendering of individual components of a
GuiObjectcan be controlled individually through transparency properties such asGuiObject.BackgroundTransparency,TextLabel.TextTransparencyandImageLabel.ImageTransparency.When this property is
false, theGuiObjectwill be ignored by layout structures such asUIListLayout,UIGridLayout, andUITableLayout. In other words, the space that the element would otherwise occupy in the layout is used by other elements instead.ZIndex
: intDetermines the order in which aGuiObjectrenders relative to others.This property determines the order in which a
GuiObjectrenders relative to others.By default,
GuiObjectsrender in ascending priority order where those with lowerZIndexvalues are rendered under those with higher values. You can change the render order within aScreenGui,SurfaceGui, orBillboardGuiby changing the value of itsZIndexBehavior.If you are unsure if you'll need to add an element between two existing elements in the future, it's a good practice to use multiples of
100(0,100,200, etc.). This ensures a large gap of render order values which you can use for elements layered in-between other elements.See also
LayoutOrderwhich controls the sorting order of aGuiObjectwhen used with a layout structure such asUIListLayoutorUIGridLayout.
Events 16
InputBegan
GuiObject.InputBegan:Connect(function(input))Fired when a user begins interacting via a Human-Computer Interface device (Mouse button down, touch begin, keyboard button down, etc).This event fires when a user begins interacting with the
GuiObjectvia a Human-Computer Interface device (Mouse button down, touch begin, keyboard button down, etc).The
UserInputServicehas a similarly named event that is not restricted to a specific UI element:UserInputService.InputBegan.This event will always fire regardless of game state.
See also
GuiObject.InputEndedandGuiObject.InputChanged.InputChanged
GuiObject.InputChanged:Connect(function(input))Fired when a user changes how they're interacting via a Human-Computer Interface device (Mouse button down, touch begin, keyboard button down, etc).This event fires when a user changes how they're interacting via a Human-Computer Interface device (Mouse button down, touch begin, keyboard button down, etc).
The
UserInputServicehas a similarly named event that is not restricted to a specific UI element:UserInputService.InputChanged.This event will always fire regardless of game state.
See also
GuiObject.InputBeganandGuiObject.InputEnded.InputEnded
GuiObject.InputEnded:Connect(function(input))Fired when a user stops interacting via a Human-Computer Interface device (Mouse button down, touch begin, keyboard button down, etc).The InputEnded event fires when a user stops interacting via a Human-Computer Interface device (Mouse button down, touch begin, keyboard button down, etc).
The
UserInputServicehas a similarly named event that is not restricted to a specific UI element:UserInputService.InputEnded.This event will always fire regardless of game state.
See also
GuiObject.InputBeganandGuiObject.InputChanged.MouseEnter
GuiObject.MouseEnter:Connect(function(x, y))Fires when a user moves their mouse into a GUI element.The MouseEnter event fires when a user moves their mouse into a
GuiObjectelement.Please do not rely on the
xandyarguments passed by this event as a fool-proof way to determine where the user's mouse is when it enters a GUI. These coordinates may vary even when the mouse enters the GUI via the same edge - particularly when the mouse enters the element quickly. This is due to the fact the coordinates indicate the position of the mouse when the event fires rather than the exact moment the mouse enters the GUI.This event fires even when the GUI element renders beneath another element.
If you would like to track when a user's mouse leaves a GUI element, you can use the
GuiObject.MouseLeaveevent.See Also
MouseLeave
GuiObject.MouseLeave:Connect(function(x, y))Fires when a user moves their mouse out of a GUI element.The MouseLeave event fires when a user moves their mouse out of a
GuiObjectelement.Please do not rely on the
xandyarguments passed by this event as a fool-proof way to determine where the user's mouse is when it leaves a GUI. These coordinates may vary even when the mouse leaves the GUI via the same edge - particularly when the mouse leaves the element quickly. This is due to the fact the coordinates indicate the position of the mouse when the event fires rather than the exact moment the mouse leaves the GUI.This event fires even when the GUI element renders beneath another element.
See Also
MouseMoved
GuiObject.MouseMoved:Connect(function(x, y))Fires whenever a user moves their mouse while it is inside a GUI element.Fires whenever a user moves their mouse while it is inside a
GuiObjectelement. It is similar toMouse.Move, which fires regardless whether the user's mouse is over a GUI element.Note, this event fires when the mouse's position is updated, therefore it will fire repeatedly while being moved.
The
xandyarguments indicate the updated screen coordinates of the user's mouse in pixels. These can be useful to determine the mouse's location on the GUI, screen, and delta since the mouse's previous position if it is being tracked in a global variable.The code below demonstrates how to determine the
Vector2offset of the user's mouse relative to a GUI element.AbsolutePositionis measured inside the screen's GUI inset, while thexandyarguments of this event are screen coordinates that include it, so the sample callsGetGuiInset()to reconcile the two spaces instead of assuming a fixed inset size.local Players = game:GetService("Players") local GuiService = game:GetService("GuiService") local CustomScrollingFrame = script.Parent local SubFrame = CustomScrollingFrame:FindFirstChild("SubFrame") local mouse = Players.LocalPlayer:GetMouse() local function getPosition(X, Y) local topLeftInset = GuiService:GetGuiInset() local gui_X = CustomScrollingFrame.AbsolutePosition.X local gui_Y = CustomScrollingFrame.AbsolutePosition.Y local pos = Vector2.new(math.abs(X - gui_X), math.abs(Y - gui_Y - topLeftInset.Y)) print(pos) end CustomScrollingFrame.MouseMoved:Connect(getPosition)Note that this event may not fire exactly when the user's mouse enters or exits a GUI element. Therefore, the
xandyarguments may not match up perfectly to the coordinates of the GUI's edges.See Also
MouseWheelBackward
GuiObject.MouseWheelBackward:Connect(function(x, y))Fires when a user scrolls their mouse wheel back when the mouse is over a GUI element.The WheelBackward event fires when a user scrolls their mouse wheel back when the mouse is over a
GuiObjectelement. It is similar toMouse.WheelBackward, which fires regardless whether the user's mouse is over a GUI element.This event fires merely as an indicator of the wheel's backward movement. This means that the
xandymouse coordinate arguments don't change as a result of this event. These coordinates only change when the mouse moves, which can be tracked by theGuiObject.MouseMovedevent.See Also
MouseWheelForward
GuiObject.MouseWheelForward:Connect(function(x, y))Fires when a user scrolls their mouse wheel forward when the mouse is over a GUI element.The WheelForward event fires when a user scrolls their mouse wheel forward when the mouse is over a
GuiObjectelement. It is similar toMouse.WheelForward, which fires regardless whether the user's mouse is over a GUI element.This event fires merely as an indicator of the wheel's forward movement. This means that the X and Y mouse coordinate arguments do not change as a result of this event. These coordinates only change when the mouse moves, which can be tracked by the
GuiObject.MouseMovedevent.See Also
SelectionGained
GuiObject.SelectionGained:Connect(function())Fired when the GuiObject is being focused on with the Gamepad selector.This event fires when the Gamepad selector starts focusing on the
GuiObject.If you want to check from the Gamepad select stops focusing on the GUI element, you can use the
GuiObject.SelectionLostevent.When a GUI gains selection focus, the value of the
SelectedObjectproperty also changes to the that gains selection. To determine which GUI gained selection, check the value of this property.SelectionLost
GuiObject.SelectionLost:Connect(function())Fired when the Gamepad selector stops focusing on the GuiObject.This event fires when the Gamepad selector stops focusing on the
GuiObject.If you want to check from the Gamepad select starts focusing on the GUI element, you can use the
GuiObject.SelectionGainedevent.When a GUI loses selection focus, the value of the
SelectionObjectproperty changes either tonilor to the GUI element that gains selection focus. To determine which GUI gained selection, or if no GUI is selected, check the value of this property.TouchLongPress
GuiObject.TouchLongPress:Connect(function(touchPositions, state))Fires when the player starts, continues and stops long-pressing the UI element.This event fires after a brief moment when the player holds their finger on the UI element using a touch-enabled device. It fires with a table of
Vector2that describe the relative screen positions of the fingers involved in the gesture. In addition, it fires multiple times:UserInputState.Beginafter a brief delay,UserInputState.Changeif the player moves their finger during the gesture, and finallyUserInputState.End. The delay is platform dependent; in Studio it is a little longer than one second.TouchPan
GuiObject.TouchPan:Connect(function(touchPositions, totalTranslation, velocity, state))Fires when the player moves their finger on the UI element.This event fires when the player moves their finger on the UI element using a touch-enabled device. It fires shortly before
GuiObject.TouchSwipewould, and does not fire withGuiObject.TouchTap. This event is useful for allowing the player to manipulate the position of UI elements on the screen.This event fires with a table of
Vector2that describe the relative screen positions of the fingers involved in the gesture. In addition, it fires multiple times:UserInputState.Beginafter a brief delay,UserInputState.Changewhen the player moves their finger during the gesture, and finally withUserInputState.End.TouchPinch
GuiObject.TouchPinch:Connect(function(touchPositions, scale, velocity, state))Fires when the player performs a pinch or pull gesture using two fingers on the UI element.This event fires when the player uses two fingers to make a pinch or pull gesture on the UI element using a touch-enabled device. A pinch happens when two or more fingers move closer together, and a pull happens when they move apart. This event fires in conjunction with
GuiObject.TouchPan. This event is useful for allowing the player to manipulate the scale (size) of UI elements on the screen, and is most often used for zooming features.This event fires with a table of
Vector2that describe the relative screen positions of the fingers involved in the gesture. In addition, it fires multiple times:UserInputState.Beginafter a brief delay,UserInputState.Changewhen the player moves a finger during the gesture, and finally withUserInputState.End. It should be noted that the scale should be used multiplicatively.TouchRotate
GuiObject.TouchRotate:Connect(function(touchPositions, rotation, velocity, state))Fires when the player performs a rotation gesture using two fingers on the UI element.This event fires when the player uses two fingers to make a pinch or pull gesture on the UI element using a touch-enabled device. Rotation occurs when the angle of the line between two fingers changes. This event fires in conjunction with
GuiObject.TouchPan. This event is useful for allowing the player to manipulate the rotation of UI elements on the screen.This event fires with a table of
Vector2that describe the relative screen positions of the fingers involved in the gesture. In addition, it fires multiple times:UserInputState.Beginafter a brief delay,UserInputState.Changewhen the player moves a finger during the gesture, and finally withUserInputState.End.TouchSwipe
GuiObject.TouchSwipe:Connect(function(swipeDirection, numberOfTouches))Fires when the player performs a swipe gesture on the UI element.This event fires when the player performs a swipe gesture on the UI element using a touch-enabled device. It fires with the direction of the gesture (Up, Down, Left or Right) and the number of touch points involved in the gesture. Swipe gestures are often used to change tabs in mobile UIs.
TouchTap
GuiObject.TouchTap:Connect(function(touchPositions))Fires when the player performs a tap gesture on the UI element.This event fires when the player performs a tap gesture on the UI element using a touch-enabled device. A tap is a quick single touch without any movement involved (a longer press would fire
GuiObject.TouchLongPress, and moving during the touch would fireGuiObject.TouchPanand/orGuiObject.TouchSwipe). It fires with a table ofVector2objects that describe the relative positions of the fingers involved in the gesture.
GuiObject also has every member of GuiBase2d. 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.