TextLabel
A TextLabel renders a rectangle, like a Frame, with styled text. The rectangle can be used to define text boundaries, text scaling (TextScaled), wrapping (TextWrapped), and alignment (TextXAlignment and/or TextYAlignment).
This class contains properties that control the display of the text, such as Font and TextColor3. To display only text and hide the background rectangle, set BackgroundTransparency to 1.
A UITextSizeConstraint object can be used to constrain the size of text with TextScaled enabled. It is recommended that the size of text is no lower than 9, otherwise it may not be visible to many users.
Summary
Properties
A copy of TextLabel.Text that contains exactly what is being rendered by the TextLabel.
Determines the font used to render text.
Determines the font used to render text.
Scales the spacing between lines of text in the TextLabel.
Sets whether a TextLabel should be GuiBase2d.Localize or not.
The maximum number of graphemes the TextLabel can show.
Determines whether the TextLabel renders its text using rich text formatting.
Determines the string rendered by the TextLabel.
Read-only property which reflects the absolute size of rendered text in offsets.
Determines the color of rendered text.
Direction in which the text is rendered.
A boolean representation of whether the label's text fits within the size of it.
Changes whether text is resized to fit within the TextLabel.
Determines the line height of text in offsets.
Determines the color of the text stroke (outline).
Determines the transparency of the text stroke (outline).
Determines the transparency of rendered text.
Controls the truncation of the text displayed in the TextLabel.
Determines if text wraps to multiple lines within the TextLabel element's space, truncating excess text.
Determines the horizontal alignment of rendered text.
Determines the vertical alignment of rendered text.
Determines whether this UI element sinks input.
Determines the origin point of a GuiObject, relative to its absolute size.
Determines whether resizing occurs based on child content.
Determines the GuiObject background color.
Determines the transparency of the GuiObject background and border.
Determines the color of the GuiObject border.
Determines in what manner the GuiObject border is laid out relative to its dimensions.
Determines the pixel width of the GuiObject border.
Determines if descendant GuiObjects outside of the bounds of a parent GUI element should render.
Determines whether the player's mouse is being actively pressed on the GuiObject or not.
Determines whether the GuiButton can be interacted with or not, or if the GuiState of the GuiObject is changing or not.
Controls the sort order of the GuiObject when used with a UIGridStyleLayout.
Sets the GuiObject which will be selected when the gamepad selector is moved downward.
Sets the GuiObject which will be selected when the gamepad selector is moved to the left.
Sets the GuiObject which will be selected when the gamepad selector is moved to the right.
Sets the GuiObject which will be selected when the gamepad selector is moved upward.
Determines the pixel and scalar position of the GuiObject.
Determines the number of degrees by which the GuiObject is rotated.
Determine whether the GuiObject can be selected by a gamepad.
Overrides the default selection adornment used for gamepads.
The order of GuiObjects selected by the gamepad UI selection.
Determines the pixel and scalar size of the GuiObject.
Sets the Size axes that the GuiObject will be based on, relative to the size of its parent.
A mixed property of BackgroundTransparency and TextTransparency.
Determines whether the GuiObject and its descendants will be rendered.
Determines the order in which a GuiObject renders relative to others.
Describes the actual screen position of a GuiBase2d element, in pixels.
Describes the actual screen rotation of a GuiBase2d element, in degrees.
Describes the actual screen size of a GuiBase2d element, in pixels.
When set to true, localization will be applied to this GuiBase2d and its descendants.
A reference to a LocalizationTable to be used to apply automated localization to this GuiBase2d and its descendants.
Customizes gamepad selection behavior in the down direction.
Customizes gamepad selection behavior in the left direction.
Customizes gamepad selection behavior in the right direction.
Customizes gamepad selection behavior in the up direction.
Allows customization of gamepad selection movement.
Methods
Methods inherited from GuiObject- TweenPosition(endPosition : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : bool,callback : function):bool
Smoothly moves a GUI to a new UDim2.
- TweenSize(endSize : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : bool,callback : function):bool
- TweenSizeAndPosition(endSize : UDim2,endPosition : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : bool,callback : function):bool
Smoothly moves a GUI to a new size and position.
Events
Events inherited from GuiObjectFired when a user begins interacting via a Human-Computer Interface device (Mouse button down, touch begin, keyboard button down, etc).
Fired when a user changes how they're interacting via a Human-Computer Interface device (Mouse button down, touch begin, keyboard button down, etc).
Fired when a user stops interacting via a Human-Computer Interface device (Mouse button down, touch begin, keyboard button down, etc).
Fires when a user moves their mouse into a GUI element.
Fires when a user moves their mouse out of a GUI element.
Fires whenever a user moves their mouse while it is inside a GUI element.
Fires when a user scrolls their mouse wheel back when the mouse is over a GUI element.
Fires when a user scrolls their mouse wheel forward when the mouse is over a GUI element.
Fired when the GuiObject is being focused on with the Gamepad selector.
Fired when the Gamepad selector stops focusing on the GuiObject.
Fires when the player starts, continues and stops long-pressing the UI element.
- TouchPan(touchPositions : Array,totalTranslation : Vector2,velocity : Vector2,state : Enum.UserInputState):RBXScriptSignal
Fires when the player moves their finger on the UI element.
- TouchPinch(touchPositions : Array,scale : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal
Fires when the player performs a pinch or pull gesture using two fingers on the UI element.
- TouchRotate(touchPositions : Array,rotation : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal
Fires when the player performs a rotation gesture using two fingers on the UI element.
Fires when the player performs a swipe gesture on the UI element.
Fires when the player performs a tap gesture on the UI element.
- SelectionChanged(amISelected : bool,previousSelection : GuiObject,newSelection : GuiObject):RBXScriptSignal
Fires when the gamepad selection moves to, leaves, or changes within the connected GuiBase2d or any descendant GuiObjects.
Properties
ContentText
This property provides a copy of Text that contains exactly what is being rendered by the TextLabel. 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! |
Font
This property selects one of several pre-defined fonts with which the TextLabel will render its text. Some fonts have bold, italic and/or light variants.
With the exception of the Enum.Font.Legacy font, each font will render text with the line height equal to the TextSize property.
The Enum.Font.Code font 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 the TextSize property.
This property is kept in sync with the FontFace property.
Code Samples
local frame = script.Parent
-- Create a TextLabel displaying each font
for _, font in pairs(Enum.Font:GetEnumItems()) do
local textLabel = Instance.new("TextLabel")
textLabel.Name = font.Name
-- Set the text properties
textLabel.Text = font.Name
textLabel.Font = font
-- Some rendering properties
textLabel.TextSize = 24
textLabel.TextXAlignment = Enum.TextXAlignment.Left
-- Size the frame equal to the height of the text
textLabel.Size = UDim2.new(1, 0, 0, textLabel.TextSize)
-- Add to the parent frame
textLabel.Parent = frame
end
-- Layout the frames in a list (if they aren't already)
if not frame:FindFirstChildOfClass("UIListLayout") then
local uiListLayout = Instance.new("UIListLayout")
uiListLayout.Parent = frame
end
FontFace
This property is similar to the Font property but allows setting fonts that don't exist in Enum.Font.
This property is kept in sync with the Font property, such that when setting FontFace, the font is set to the corresponding Enum.Font value or to Enum.Font.Unknown if there are no matches.
LineHeight
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 TextLabel. Valid values range from 1.0 to 3.0, defaulting to 1.0.
MaxVisibleGraphemes
This property controls the maximum number of graphemes (or units of text) that are shown on the TextLabel. 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 -1 disables the limit and shows the entirety of the Text.
OpenTypeFeatures
OpenTypeFeaturesError
RichText
This property determines whether the TextLabel renders 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 Text string.
Text
This property determines the text content rendered by the TextLabel. The visual properties of the string rendered to the screen is determined by TextColor3, TextTransparency, TextSize, Font, TextScaled, TextWrapped, TextXAlignment and TextYAlignment.
It is possible to render emoji such as 🔒 and other symbols which aren't affected by the TextColor3 property. These can be pasted into Script and LocalScript objects, 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.
Code Samples
local TweenService = game:GetService("TweenService")
local textLabel = script.Parent
local content = {
"Welcome to my game!",
"Be sure to have fun!",
"Please give suggestions!",
"Be nice to other players!",
"Don't grief other players!",
"Check out the shop!",
"Tip: Don't die!",
}
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local RNG = Random.new()
local fadeIn = TweenService:Create(textLabel, tweenInfo, {
TextTransparency = 0,
})
local fadeOut = TweenService:Create(textLabel, tweenInfo, {
TextTransparency = 1,
})
local lastIndex
while true do
-- Step 0: Fade out before doing anything
fadeOut:Play()
task.wait(tweenInfo.Time)
-- Step 1: pick content that wasn't the last displayed
local index
repeat
index = RNG:NextInteger(1, #content)
until lastIndex ~= index
-- Make sure we don't show the same thing next time
lastIndex = index
-- Step 2: show the content
textLabel.Text = content[index]
fadeIn:Play()
task.wait(tweenInfo.Time + 1)
end
local textLabel = script.Parent
local moods = {
["happy"] = "😃",
["sad"] = "😢",
["neutral"] = "😐",
["tired"] = "😫",
}
while true do
for mood, face in pairs(moods) do
textLabel.Text = "I am feeling " .. mood .. "! " .. face
task.wait(1)
end
end
TextBounds
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 what TextBounds will be given a string, Font, TextSize, and frame size.
TextColor3
This property determines the color of all the text rendered by the TextLabel element.
Code Samples
-- Place this code in a LocalScript within a TextLabel/TextButton
local textLabel = script.Parent
-- Some colors we'll use with TextColor3
local colorNormal = Color3.new(0, 0, 0) -- black
local colorSoon = Color3.new(1, 0.5, 0.5) -- red
local colorDone = Color3.new(0.5, 1, 0.5) -- green
-- Loop infinitely
while true do
-- Count backwards from 10 to 1
for i = 10, 1, -1 do
-- Set the text
textLabel.Text = "Time: " .. i
-- Set the color based on how much time is left
if i > 3 then
textLabel.TextColor3 = colorNormal
else
textLabel.TextColor3 = colorSoon
end
task.wait(1)
end
textLabel.Text = "GO!"
textLabel.TextColor3 = colorDone
task.wait(2)
end
TextScaled
This property determines whether text is scaled so that it fills the label's entire space. When enabled, TextSize is ignored and TextWrapped is automatically enabled. This property is useful for rendering text elements within BillboardGuis. 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.
Automatic Sizing
It's recommended that you avoid usage of TextScaled and adjust UI to take advantage of the AutomaticSize property instead. Here are the core differences between the two properties:
TextScaled scales the content (text) to accommodate the UI. Without careful consideration, some text may become unreadable if scaled too small.
AutomaticSize resizes 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 AutomaticSize and TextScaled and to the same TextLabel. AutomaticSize determines the maximum amount of available space that a GuiObject can use (in this case, text), while TextScaled uses the available space determined by AutomaticSize to scale the font size up to the maximum font size (100) if there are no size constraints.
TextSize
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 Enum.Font.Legacy font does not hold this property.
TextStrokeColor3
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
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 TextStrokeTransparency to a value in the range of 0.75 to 1 for more a more subtle effect.
As a powerful alternative which supports color gradients, see UIStroke.
TextTransparency
This property determines the transparency of all the text rendered by the TextLabel.
TextWrapped
When enabled, this property will render text on multiple lines within a TextLabel 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 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
This property determines the horizontal alignment of text rendered within the object's space. It is used in conjunction with TextYAlignment to fully determine text alignment on both axes.
Note that this property won't affect the read-only properties TextBounds and TextFits.
TextYAlignment
This property determines the vertical alignment of text rendered within the object's space. It is used in conjunction with TextXAlignment to fully determine text alignment on both axes.
Note that this property won't affect the read-only properties TextBounds and TextFits.