Class · inherits GuiButton
TextButton
A 2D user interface element that displays interactive text.
About TextButton
A TextButton behaves similarly to TextLabel in regards to
rendering, with the additional behaviors of a GuiButton.
You can disable text rendering by setting
TextTransparency to 1. This will result
in a plain rectangle that can be used as a button.
Properties 23
ContentText
: stringReadOnlyNotReplicatedA copy ofTextButton.Textthat contains exactly what is being rendered by theTextButton.This property provides a copy of
Textthat contains exactly what is being rendered by theTextButton. This is useful for eliminating style tags used for rich text markup; for example, whenRichTextis enabled, theContentTextproperty shows the text as it appears to the user.Font
: Enum.FontHiddenNotReplicatedDetermines the font used to render text.This property selects one of several pre-defined fonts with which the
TextButtonwill render its text. Some fonts have bold, italic and/or light variants.With the exception of the
Font.Legacyfont, each font will render text with the line height equal to theTextSizeproperty.The
Font.Codefont is the only monospace font. It has the unique property that each character has the exact same width and height ratio of 1:2, where the width of each character is approximately half theTextSizeproperty.This property is kept in sync with the
FontFaceproperty.FontFace
: Datatype.FontDetermines the font used to render text.LineHeight
: floatScales the spacing between lines of text in theTextButton.Controls the height of lines as a multiple of the font's
emsquare size by scaling the spacing between lines of text in theTextButton. Valid values range from1.0to3.0, defaulting to1.0.LocalizedText
: stringHiddenReadOnlyNotReplicatedSets whether aTextButtonshould beGuiBase2d.Localizeor not.This property sets whether a
TextButtonshould regardGuiBase2d.Localizeor not.MaxVisibleGraphemes
: intThe maximum number of graphemes theTextButtoncan show.This property controls the maximum number of graphemes (or units of text) that are shown on the
TextButton. It is primarily provided as an easy way to create a typewriter effect where the characters appear one at a time.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
-1disables the limit and shows the entirety of theText.OpenTypeFeatures
: stringApplies OpenType font features, such as stylistic sets, to the text rendered by theTextButton.A comma-separated list of OpenType feature tags applied to text rendered by the
TextButton(for example,zerofor slashed zeros). Whitespace around each tag is ignored. Defaults to an empty string, which applies no additional features.Only a supported subset of tags is applied. If a tag can't be parsed, isn't supported, or uses unsupported partial enabling with brackets, all tags are discarded.
OpenTypeFeaturesError.OpenTypeFeaturesError
: stringReadOnlyNotReplicatedRead-only property that contains the error message, if any, produced while applyingOpenTypeFeatures.Read-only message produced when a tag in
OpenTypeFeaturescan't be applied — for example, when a tag fails to parse, isn't supported, or uses unsupported partial (bracketed) enabling. Empty while the currentOpenTypeFeaturesvalue applies successfully.RichText
: booleanDetermines whether theTextButtonrenders its text using rich text formatting.This property determines whether the
TextButtonrenders its text using rich text markup to style sections of the string in bold, italics, specific colors, and more.To use rich text, simply include rich text formatting tags in the
Textstring.Text
: stringDetermines the string rendered by theTextButton.This property determines the text content rendered by the
TextButton. The visual properties of the string rendered to the screen is determined byTextColor3,TextTransparency,TextSize,Font,TextScaled,TextWrapped,TextXAlignmentandTextYAlignment.It is possible to render emoji such as 🔒 and other symbols which aren't affected by the
TextColor3property. These can be pasted intoScriptandLocalScriptobjects, as well as the field within the Properties window.This property may contain newline characters. Similarly, this property may contain a tab character, but it will render as a space instead.
TextBounds
: Vector2ReadOnlyNotReplicatedRead-only property which reflects the absolute size of rendered text in offsets.This read-only property reflects the absolute size of rendered text in offsets, meaning that if you try to fit text into a rectangle, this property would reflect the minimum dimensions of the rectangle you'd need in order to fit the text.
Using
TextService.GetTextSize, you can predict whatTextBoundswill be given a string,Font,TextSize, and frame size.TextColor3
: Color3Determines the color of rendered text.This property determines the color of all the text rendered by the
TextButtonelement.TextDirection
: TextDirectionDirection in which the text is rendered.TextDirectionin which the text is rendered.TextFits
: booleanReadOnlyNotReplicatedA boolean representation of whether the button's text fits within the size of it.TextScaled
: booleanChanges whether text is resized to fit within theTextButton.This property determines whether text is scaled so that it fills the button's entire space. When enabled,
TextSizeis ignored andTextWrappedis automatically enabled. This property is useful for rendering text elements withinBillboardGuis. When this property is used for on-screen UI, it may be helpful to use aUITextSizeConstraintto restrict the range of possible text sizes.Automatic Sizing
It's recommended that you avoid usage of
TextScaledand adjust UI to take advantage of theAutomaticSizeproperty instead. Here are the core differences between the two properties:TextScaledscales the content (text) to accommodate the UI. Without careful consideration, some text may become unreadable if scaled too small.AutomaticSizeresizes the UI to accommodate content while maintaining a consistent font size. For more information, see here.
Additionally, it's recommended that you avoid applying both
AutomaticSizeandTextScaledand to the sameTextButton.AutomaticSizedetermines the maximum amount of available space that aGuiObjectcan use (in this case, text), whileTextScaleduses the available space determined byAutomaticSizeto scale the font size up to the maximum font size (100) if there are no size constraints.TextSize
: floatDetermines the line height of text in offsets.This property determines the height of one line of rendered text. The unit is in offsets, not points (which is used in most document editing programs). The
Font.Legacyfont does not hold this property.TextStrokeColor3
: Color3Determines the color of the text stroke (outline).This property sets the color of the stroke, or outline, of rendered text. Along with
TextStrokeTransparency, it determines the final visual appearance of the text stroke.As a powerful alternative which supports color gradients, see
UIStroke.TextStrokeTransparency
: floatDetermines the transparency of the text stroke (outline).This property sets the transparency of the stroke, or outline, of rendered text. Along with
TextStrokeColor3, it determines the final visual appearance of the text stroke.Note that text stroke is multiple renderings of the same transparency, so this property is essentially multiplicative on itself four times over. Therefore, it's recommended to set
TextStrokeTransparencyto a value in the range of0.75to1for more a more subtle effect.As a powerful alternative which supports color gradients, see
UIStroke.TextTransparency
: floatDetermines the transparency of rendered text.This property determines the transparency of all the text rendered by the
TextButton.TextTruncate
: TextTruncateControls the truncation of the text displayed in theTextButton.TextWrapped
: booleanDetermines if text wraps to multiple lines within theTextButtonelement's space, truncating excess text.When enabled, this property will render text on multiple lines within a
TextButtonelement's space so thatTextBoundswill never exceed theGuiBase2d.AbsoluteSizeof 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
TextBounds) to exceed the vertical height of the element (the Y component ofGuiBase2d.AbsoluteSize), then that line will not be rendered at all.TextXAlignment
: TextXAlignmentDetermines the horizontal alignment of rendered text.This property determines the horizontal alignment of text rendered within the object's space. It is used in conjunction with
TextYAlignmentto fully determine text alignment on both axes.Note that this property won't affect the read-only properties
TextBoundsandTextFits.TextYAlignment
: TextYAlignmentDetermines the vertical alignment of rendered text.This property determines the vertical alignment of text rendered within the object's space. It is used in conjunction with
TextXAlignmentto fully determine text alignment on both axes.Note that this property won't affect the read-only properties
TextBoundsandTextFits.
TextButton also has every member of GuiButton. 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.