Toggle
Method
Toggle turns the visibility of another UI element on or off when a button is clicked.
Overview
The Toggle Method connects a button (TextButton or ImageButton) to a target instance. When the button is clicked, the target's visibility is toggled. The link between the button and the target is made through an ObjectValue inside the button.
Setup
- Add the
UiUtilstag on yourTextButtonorImageButton - Add Attribute
Method=Toggle - Add an ObjectValue inside the button
- Set the ObjectValue's
Valueto the instance you want to toggle
Attributes
| Attribute | Type | Required | Description |
|---|---|---|---|
SwitchValue |
Boolean | No | If set, forces the target to this value instead of toggling on/off |
Supported Target Instances
The Toggle Method works with the following instance types:
| Instance | Property toggled |
|---|---|
ScreenGui |
Enabled |
Frame |
Visible |
CanvasGroup |
Visible |
ScrollingFrame |
Visible |
ViewportFrame |
Visible |
TextLabel |
Visible |
TextButton |
Visible |
TextBox |
Visible |
ImageLabel |
Visible |
ImageButton |
Visible |
VideoFrame |
Visible |
Examples
Toggle a Frame's visibility:
- Tag:
UiUtilson your button Method=Toggle- ObjectValue inside the button →
Valuepointing to the Frame
Force a ScreenGui to always enable on click:
- Tag:
UiUtilson your button Method=ToggleSwitchValue=true- ObjectValue inside the button →
Valuepointing to the ScreenGui
Notes
- The instance with the Toggle Method must be a
TextButtonorImageButton— other instance types will be rejected - The ObjectValue must be a direct child of the button and its
Valuemust point to a valid instance - The target instance must be one of the supported types listed above
- The connection is automatically cleaned up when the button is destroyed
- If the ObjectValue is missing:
No ObjectValue found for switch - If the ObjectValue has no Value:
No value found in ObjectValue - If the target type isn't supported:
No value found for InstanceType - If the instance isn't a button:
Your instance need to be a TextButton or an ImageButton