TextBox¶
A 2D user interface element that displays player-editable text.
Description¶
A TextBox allows the player to provide text input. It behaves similarly to a
TextButton, except that a single TextBox can be put in focus by
clicking, tapping, or gamepad selection. While in focus, the player can use a
keyboard to change the Text property.
- If there is no text, the PlaceholderText will be visible. This is useful prompting players of the kind or format of data they should input.
- By default, the ClearTextOnFocus property
is enabled and ensures there is no existing text when a
TextBoxis focused. This may not be desirable for text that should be editable by the player. - The MultiLine property allows players to enter
multiple lines of text with newline characters (
\n).
Focus State¶
It is possible to detect and change the focus state of a TextBox:
- You can use CaptureFocus when a dialogue
appears so that the player doesn't have to click on a
TextBoxwhen it becomes available; you can use ContextActionService.BindAction() to bind a certain key to focus aTextBoxusing this function. When aTextBoxcomes into focus, the Focused event fires. - You can detect if a certain
TextBoxis in focus by using IsFocused. Alternatively, UserInputService.GetFocusedTextBox() can be used to check if anyTextBoxis in focus. - When the player is done inputting text, the FocusLost event fires, indicating if the player pressed Enter to submit text along with the InputObject that caused the loss of focus. When using on-screen keyboards on mobile and console, ReturnPressedFromOnScreenKeyboard may also fire.
- If some more important matter comes up during gameplay, you can
ReleaseFocus of the
TextBoxso that a player's keyboard input returns to your game.
Text Editing¶
A TextBox supports text selection through its
CursorPosition and
SelectionStart properties. Using
GetPropertyChangedSignal, you can
detect when a selection changes. Additionally, it is possible for players to
copy and paste text within a TextBox, enabling basic clipboard support. When
the cursor moves outside the visible area while typing or navigating, the
TextBox automatically scrolls its viewport to keep the cursor in view.
Text Filtering Notice Games that facilitate player-to-player communication using text, such as custom chat or nametags, must properly filter such text using TextService.FilterStringAsync() or Chat.FilterStringAsync(). If this is not properly done, your game may receive moderation action.
Inheritance¶
Object → Instance → GuiBase → GuiBase2d → GuiObject → TextBox
Nova inheritance: Instance → GuiBase → GuiBase2d → GuiObject → TextBox
Properties¶
ClearTextOnFocus Supported Property Determines whether clicking on the TextBox will clear its TextBox.Text property.
Determines whether clicking on the TextBox will clear its
TextBox.Text property
ContentText Supported Property A copy of TextBox.Text that contains exactly what is being rendered by the TextBox.
A copy of TextBox.Text that contains exactly what is being rendered by the TextBox.
This property provides a copy of Text that contains exactly what is being rendered by the TextBox. This is useful for eliminating style tags used for rich text markup; for example, when RichText is enabled, the ContentText property shows the text as it appears to the user.
| RichText | Text | ContentText |
|---|---|---|
false |
<b>Hello,<br/> world!</b> | <b>Hello,<br/> world!</b> |
true |
<b>Hello,<br/> world!</b> | Hello, world! |
CursorPosition Supported Property Determines the offset of the text cursor in bytes, or -1 if there is no cursor.
Determines the offset of the text cursor in bytes, or -1 if there is no
cursor.
This property determines the offset of the text cursor in bytes, or -1
if the TextBox is not currently being edited. A value of 1 represents
the position before the first byte in the Text
property. When used in conjunction with the
SelectionStart property, it is possible to
both get and set selected text within a TextBox.
Note that the units of this property are bytes and that many unicode
characters such as emoji are longer than 1 byte. For instance, if a player
types in "Hello👋" ("Hello" immediately followed by the waving hand sign),
the cursor position would be 10, not 7, since the emoji uses 4 bytes.
Font Supported Property Determines the font used to render text.
Determines the font used to render text.
This property selects one of several pre-defined Font fonts with which the UI element will render its text. Some fonts have bold, italic, and/or light variants.
This property is kept in sync with the TextBox.FontFace property.
When setting Font, the FontFace property will
be set to Font.fromEnum(value).
FontFace Supported Property Determines the font face used to render text.
Determines the font face used to render text.
This property is similar to the Font property but allows setting fonts that don't exist in Font.
This property is kept in sync with the TextBox.Font property. When
setting FontFace, the Font property is set to the
corresponding enum value, or to Font.Unknown if there are no
matches.
FontSize Supported Property Deprecated Determines the font size of a TextBox object.
LineHeight Supported Property Scales the spacing between lines of text in the TextBox.
Scales the spacing between lines of text in the TextBox.
Controls the height of lines, as a multiple of the font's em square size,
by scaling the spacing between lines of text in the TextBox. Valid
values range from 1.0 (default) to 3.0.
MaxVisibleGraphemes Supported Property The maximum number of graphemes the TextBox can show.
The maximum number of graphemes the TextBox can show.
This property controls the maximum number of graphemes (or units of text)
that are shown on the TextBox, regardless of whether it's showing the
PlaceholderText or
Text.
Changing the property does not change the position or size of the visible graphemes; the layout will be calculated as if all graphemes are visible.
Setting the property to -1 disables the limit and shows the entirety of
the Text.
MultiLine Supported Property When set to true, text inside a TextBox is able to move onto multiple lines.
When set to true, text inside a TextBox is able to move onto multiple
lines. This also enables players to use the Enter key to move
onto a new line.
PlaceholderColor3 Supported Property Sets the text color that gets used when no text has been entered into the TextBox.
Sets the text color that gets used when no text has been entered into the
TextBox.
PlaceholderText Supported Property Sets the text that gets displayed when no text has been entered into the TextBox.
Sets the text that gets displayed when no text has been entered into the
TextBox.
RichText Supported Property Determines whether the TextBox renders the Text string using rich text formatting.
This property determines whether the TextBox renders the
Text string using
rich text formatting. Rich text uses simple
markup tags to style sections of the string in bold, italics, specific
colors, and more.
Note that when the TextBox has this property enabled and the box gains
focus, the player will be able to edit and interact with the complete XML
string, including all of the formatting tags. When focus is lost, the text
will automatically parse and render the tags as rich text.
SelectionStart Supported Property Determines the starting position of a text selection.
Determines the starting position of a text selection.
Determines the starting position of a text selection, or -1 if the
TextBox has no range of selected text. This property uses the same
positioning logic as CursorPosition.
SelectionStart will be greater than
CursorPosition if the cursor is at the
beginning of a selection, and less than
CursorPosition if the cursor is at the end.
Text Supported Property Determines the string rendered by the TextBox element.
Determines the string rendered by the TextBox element.
This property determines the text content rendered by the TextBox
element. The visual properties of the string rendered to the screen is
determined by TextColor3,
TextTransparency,
TextSize, FontFace, and
other properties.
It is possible to render emoji such as 👋 and other symbols. These special symbols aren't affected by the TextColor3 property.
This property may contain newline characters, but it is not possible to type newline characters within the Properties window. Similarly, this property may contain a tab character, but it will render as a space instead.
TextBounds Supported Property The size of a TextBox element's text in offsets.
The size of a TextBox element's text in offsets.
This read-only property reflects the absolute size of rendered text in offsets. In other words, if you were to try to fit text into a rectangle, this property would reflect the minimum dimensions of the rectangle you would need in order to fit the text.
Using TextService.GetTextSize(), you can predict what TextBounds
will be on a TextLabel given a string, Font,
TextSize and frame size.
TextColor Supported Property Deprecated Deprecated. Use TextColor3 instead
Deprecated. Use TextColor3 instead
TextColor3 Supported Property Determines the color of non-placeholder rendered text.
Determines the color of non-placeholder rendered text.
This property determines the color of non-placeholder text rendered by the
TextBox. Text is rendered after the text stroke.
TextEditable Supported Property Determines whether the player can change the Text.
Determines whether the player can change the Text.
This property determines whether the player can change the Text through input. It is recommended to disable ClearTextOnFocus when this property is disabled, otherwise the text can be cleared on-focus.
TextFits Supported Property Whether the text fits within the constraints of the TextBox.
TextScaled Supported Property Changes whether text is resized to fit within the TextBox.
Changes whether text is resized to fit within the TextBox.
This property determines whether text is scaled so that it fills the box's entire space. When enabled, TextSize is ignored and TextWrapped is automatically enabled. When this property is used for on-screen UI, it may be helpful to use a UITextSizeConstraint to restrict the range of possible text sizes.
See TextLabel.TextScaled for additional recommendations when using this property.
TextSize Supported Property Determine the line height of text in offsets.
Determine the line height of text in offsets.
This property determines the height in offsets of one line of rendered text. The unit is in offsets, not points as in many document editing programs.
TextStrokeColor3 Supported Property Determines the color of the text stroke (outline).
Determines the color of the text stroke (outline).
This property sets the color of the stroke (outline) of the rendered text. This property and TextStrokeTransparency determine the visual appearance of the text stroke.
TextStrokeTransparency Supported Property Determines the transparency of the text stroke (outline).
Determines the transparency of the text stroke (outline).
This property sets the transparency of the stroke (outline) of the rendered text. This property and TextStrokeColor3 determine the visual appearance of the text stroke.
Since text stroke is simply multiple renderings of the same transparency,
this property is essentially multiplicative on itself four times over; for
example a TextStrokeTransparency of 0.5 appears about the same as
TextTransparency of 0.0625, or 0.5^4.
TextTransparency Supported Property Determines the transparency of the rendered text.
Determines the transparency of the rendered text.
This property determines the transparency of all the text rendered by the
TextBox.
TextTruncate Supported Property Controls the truncation of the text displayed in the TextBox.
Controls the truncation of the text displayed in the TextBox.
TextWrap Supported Property Deprecated
No description available.
TextWrapped Supported Property Determines if text wraps to multiple lines within the TextBox element space, truncating excess text.
Determines if text wraps to multiple lines within the TextBox element
space, truncating excess text.
When enabled, this property will render text on multiple lines within a
TextBox element's space so that TextBounds
will never exceed the GuiBase2d.AbsoluteSize of the element.
This is achieved by breaking long lines of text into multiple lines. Line breaks will prefer whitespace; should a long unbroken word exceed the width of the element, that word will be broken into multiple lines.
If further line breaks would cause the vertical height of the text (the Y component of TextBox.TextBounds) to exceed the vertical height of the element (the Y component of GuiBase2d.AbsoluteSize), then that line will not be rendered at all.
TextXAlignment Supported Property Determines the horizontal alignment of the rendered text.
Determines the horizontal alignment of the rendered text.
This property determines the horizontal alignment of text rendered within
the TextBox element's space. It can be used in conjunction with
TextYAlignment to fully determine text
alignment on both axes.
This property does not affect the read-only properties TextBounds and TextFits.
TextYAlignment Supported Property Determines the vertical alignment of the rendered text.
Determines the vertical alignment of the rendered text.
This property determines the vertical alignment of text rendered within
the TextBox element's space. It can be used in conjunction with
TextXAlignment to fully determine text
alignment on both axes.
This property does not affect the read-only properties TextBounds and TextFits.
Methods¶
CaptureFocus Supported Function Forces the client to focus on the TextBox.
Forces the client to focus on the TextBox.
IsFocused Supported Function Whether the TextBox currently has focus.
Whether the TextBox currently has focus.
Returns true if the TextBox is focused or false if it is not.
ReleaseFocus Supported Function Forces the client to unfocus the TextBox.
Forces the client to unfocus the TextBox.
Forces the client to unfocus the TextBox. The submitted parameter lets
you override the enterPressed parameter in the TextBox.FocusLost
event.
Events¶
Focused Supported Event Fires when the TextBox gains focus.
Fires when the TextBox gains focus.
This event fires when the TextBox gains focus, typically when a player
clicks/taps on the TextBox to begin text entry. Also fires if TextBox
focus is forced through CaptureFocus().
This event can be used alongside FocusLost to
track when a TextBox both gains and loses focus.
FocusLost Supported Event Fires when the TextBox loses its focus.
Fires when the TextBox loses its focus.
This event fires when the TextBox loses its focus, typically when a
player clicks/taps outside of it or presses Enter. Also fires
if TextBox focus release is forced through
ReleaseFocus().
This event can be used alongside FocusLost to
track when a TextBox both gains and loses focus.
Inherited members¶
Inherited from GuiObject: 45 properties, 39 methods, 25 events. They are documented on the base class page.
7 modern Roblox member(s) are not implemented yet — expand to inspect
Members declared by Roblox's TextBox class (or by a missing base class) that Nova does not expose. Use this list to scope a migration; the compatibility guide has the recommended workaround.
Properties¶
| Member | Signature | Status | Notes | Flags |
|---|---|---|---|---|
OpenTypeFeatures |
OpenTypeFeatures: string |
Not yet | Applies OpenType typographic features to the text rendered by the TextBox. | — |
OpenTypeFeaturesError |
OpenTypeFeaturesError: string |
Not yet | Read-only property that describes why the TextBox.OpenTypeFeatures string could not be applied. | ReadOnly, NotReplicated |
ShowNativeInput |
ShowNativeInput: bool |
Not yet | If set to true, input native to the platform is used instead of Roblox's built-in keyboard. |
— |
TextDirection |
TextDirection: TextDirection |
Not yet | Direction in which the text is rendered. | — |
Methods¶
| Member | Signature | Status | Notes | Flags |
|---|---|---|---|---|
ResetKeyboardMode |
TextBox:ResetKeyboardMode(): null |
Not yet | — | RobloxScriptSecurity |
SetTextFromInput |
TextBox:SetTextFromInput(text: string): null |
Not yet | — | RobloxScriptSecurity |
Events¶
| Member | Signature | Status | Notes | Flags |
|---|---|---|---|---|
ReturnPressedFromOnScreenKeyboard |
ReturnPressedFromOnScreenKeyboard() |
Not yet | Fires when the TextBox is focused and the player presses the on-screen keyboard's return/enter button. |
— |
Roblox reference: TextBox
Generated from Nova's API dump and Roblox creator-docs. Nova-only members come from the engine's reflection metadata.