PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

TextLabel

Show deprecated

TextLabel

Show deprecated

A TextLabel renders a rectangle, like a Frame, with styled text. The rectangle can be used to define text boundaries, text scaling (TextLabel/TextScaled) and wrapping (TextLabel/TextWrapped, TextLabel/TextXAlignment, TextLabel/TextYAlignment).

This class contains properties that control the display of the text, such as TextLabel/Font and TextLabel/TextColor3. All text rendered by a single text label will have the same visual properties; multiple TextLabel objects must be used in order to render multiple styles of text. To display only text and hide the rectangle, set GuiObject/BackgroundTransparency to 1.

TextService/GetTextSize can be used to get the size (bounds) of text that would be rendered in a TextLabel given a font size, font, and frame size.

A UITextSizeConstraint object can be used to constrain the size of text with TextLabel/TextScaled enabled.

Properties

Font

Font

Determines the font used to render text.

FontSize

FontSize

[NotReplicated] [Deprecated]

Determines the height in pixels of one line of text

float

LineHeight

Scales the spacing between lines of text in the TextLabel.

string

LocalizedText

[Hidden] [ReadOnly] [NotReplicated]

Sets whether a TextLabel should be GuiBase2d/Localize or not.

string

Text

Determines the string rendered by the UI element.

Vector2

TextBounds

[ReadOnly] [NotReplicated]

The pixel size of a UI element’s text.

BrickColor

TextColor

[Hidden] [NotReplicated] [Deprecated]
Color3

TextColor3

This property determines the color of rendered text

bool

TextFits

[ReadOnly] [NotReplicated]

Enables when rendered text content does not fit within the UI element’s space.

bool

TextScaled

Determines whether text in a UI element is scaled to fill the UI element.

float

TextSize

Determine the line height of text in pixels.

Color3

TextStrokeColor3

Determines the color of the text stroke (outline).

float

TextStrokeTransparency

Determines the transparency of the text stroke (outline).

float

TextTransparency

Determines the transparency of rendered text.

TextTruncate

TextTruncate

Controls the truncation of the text displayed in this TextLabel.

bool

TextWrap

[NotReplicated] [Deprecated]

Determines if text wraps to multiple lines within the UI element space, truncating excess text

bool

TextWrapped

Determines if text wraps to multiple lines within the TextLabel|GUI element space, truncating excess text.

TextXAlignment

TextXAlignment

Determines the horizontal alignment of rendered text.

TextYAlignment

TextYAlignment

Determines the vertical alignment of rendered text.

Inherited from GuiObject: Show Hide

bool

Active

Determines whether a UI element sinks input

Vector2

AnchorPoint

Determines the origin point of a GuiObject|GUI, relative to its absolute size

BrickColor

BackgroundColor

[Hidden] [NotReplicated] [Deprecated]

Determines the color of a GuiObject|GUI's background

Color3

BackgroundColor3

Determines aGuiObject|GUI's background color

float

BackgroundTransparency

Determines the transparency of the GuiObject|GUI's background and border

BrickColor

BorderColor

[Hidden] [NotReplicated] [Deprecated]

Determines the color of a GuiObject|GUI's border

Color3

BorderColor3

Determines the color of a GuiObject|GUI's border

BorderMode

BorderMode

int

BorderSizePixel

Determines the pixel width of a GuiObject|GUI's border

bool

ClipsDescendants

Determines if descendant GuiObject|GUIs outside of the bounds of a parent GUI element should render

bool

Draggable

[Deprecated]

Determines whether a GuiObject|GUI (and its descendants) can be dragged around the screen

int

LayoutOrder

Controls the sort order of a GuiObject|GUI when used with a UIGridStyleLayout

GuiObject

NextSelectionDown

Sets the GuiObject which will be selected when the Gamepad selector is moved in this direction

GuiObject

NextSelectionLeft

Sets the GuiObject which will be selected when the Gamepad selector is moved in this direction

GuiObject

NextSelectionRight

Sets the GuiObject|GUI which will be selected when the `Enum/Gamepad selector is moved in this direction

GuiObject

NextSelectionUp

Sets the GuiObject which will be selected when the Gamepad selector is moved in this direction

UDim2

Position

Determines the pixel and scalar position of a GUI

float

Rotation

Determines the number of degrees by which a UI element is rotated

bool

Selectable

Determine whether the GuiObject|GUI can be selected by a gamepad

GuiObject

SelectionImageObject

Overrides the default selection adornment (used for gamepads)

UDim2

Size

Determine the pixel and scalar size of a GuiObject|GUI

SizeConstraint

SizeConstraint

Selects the GuiObject/Size axes that a GuiObject|GUI will be based relative to the size of its parent

float

Transparency

[Hidden] [NotReplicated]

A mixed property of BackgroundTransparency and TextTransparency

bool

Visible

Determines whether a GuiObject/GUI and its descendants will be rendered

int

ZIndex

Determines the order in which a GuiObject|GUI renders relative to other GUIs

Inherited from GuiBase2d: Show Hide

Vector2

AbsolutePosition

[ReadOnly] [NotReplicated]

Describes the actual screen position of a UI element, in pixels.

float

AbsoluteRotation

[ReadOnly] [NotReplicated]

Describes the actual screen rotation of a UI element, in degrees.

Vector2

AbsoluteSize

[ReadOnly] [NotReplicated]

Describes the actual screen size of a UI element, in pixels.

bool

AutoLocalize

When set to true, localization will be applied to this GuiBase2d and its descendants based on the GuiBase2d/RootLocalizationTable specified for this GuiBase2d.

bool

Localize

[Hidden] [NotReplicated] [Deprecated]

Automatically set to true when a LocalizationTable’s Root targets this object, or an ancestor of this object.

LocalizationTable

RootLocalizationTable

A reference to a LocalizationTable to be used to apply automated localization to this GuiBase2d and its descendants.

Inherited from Instance: Show Hide

bool

Archivable

Determines if an Instance can be cloned using /Instance/Clone or saved to file.

string

ClassName

[ReadOnly] [NotReplicated]

A read-only string representing the class this Instance belongs to

int

DataCost

[ReadOnly] [NotReplicated] [Deprecated]

The cost of saving the instance using data persistence.

string

Name

A non-unique identifier of the Instance

Instance

Parent

Determines the hierarchical parent of the Instance

bool

RobloxLocked

If true, the Instance and its descendants cannot be indexed or edited by a Script or LocalScript and will throw an error if it is attempted

bool

archivable

[Hidden] [NotReplicated] [Deprecated]
string

className

[ReadOnly] [NotReplicated] [Deprecated]

Functions

Inherited from GuiObject: Show Hide

bool

TweenPosition ( UDim2 endPosition , EasingDirection easingDirection , EasingStyle easingStyle , float time , bool override , Function callback )

Smoothly moves a GUI to a new DataType/UDim2

bool

TweenSize ( UDim2 endSize , EasingDirection easingDirection , EasingStyle easingStyle , float time , bool override , Function callback )

Smoothly resizes a GUI to a new DataType/UDim2

bool

TweenSizeAndPosition ( UDim2 endSize , UDim2 endPosition , EasingDirection easingDirection , EasingStyle easingStyle , float time , bool override , Function callback )

Smoothly moves a GUI to a new size and position

Inherited from Instance: Show Hide

void

ClearAllChildren ( )

This function destroys all of an Instance's children.

Instance

Clone ( )

Create a deep copy of a Roblox instance and descendants where Archivable = true.

void

Destroy ( )

Sets the Instance/Parent property to nil, locks the Instance/Parent property, disconnects all connections and calls Destroy on all children.

Instance

FindFirstAncestor ( string name )

Returns the first ancestor of the Instance whose Instance/Name is equal to the given name.

Instance

FindFirstAncestorOfClass ( string className )

Returns the first ancestor of the Instance whose Instance/ClassName is equal to the given className.

Instance

FindFirstAncestorWhichIsA ( string className )

Returns the first ancestor of the Instance for whom Instance/IsA returns true for the given className.

Instance

FindFirstChild ( string name , bool recursive )

Returns the first child of the Instance found with the given name.

Instance

FindFirstChildOfClass ( string className )

Returns the first child of the Instance whose Instance/ClassName|ClassName is equal to the given className.

Instance

FindFirstChildWhichIsA ( string className , bool recursive )

Returns the first child of the Instance for whom Instance/IsA returns true for the given className.

Variant

GetAttribute ( string attribute )

RBXScriptSignal

GetAttributeChangedSignal ( string attribute )

Dictionary

GetAttributes ( )

Objects

GetChildren ( )

Returns an array containing all of the Instance's children.

string

GetDebugId ( int scopeLength )

[NotBrowsable]

Returns a coded string of the Instances DebugId used internally by Roblox.

Array

GetDescendants ( )

[CustomLuaState]

Returns an array containing all of the descendants of the instance

string

GetFullName ( )

Returns a string describing the Instance's ancestry.

RBXScriptSignal

GetPropertyChangedSignal ( string property )

Get an event that fires when a given property of an object changes.

bool

IsA ( string className )

[CustomLuaState]

Returns true if an Instance's class matches or inherits from a given class

bool

IsAncestorOf ( Instance descendant )

Returns true if an Instance is an ancestor of the given descendant.

bool

IsDescendantOf ( Instance ancestor )

Returns true if an Instance is a descendant of the given ancestor.

void

Remove ( )

[Deprecated]

Sets the object’s Parent to nil, and does the same for all its descendants.

void

SetAttribute ( string attribute , Variant value )

Instance

WaitForChild ( string childName , double timeOut )

[CustomLuaState] [CanYield]

Returns the child of the Instance with the given name. If the child does not exist, it will yield the current thread until it does.

Objects

children ( )

[Deprecated]

Returns an array of the object’s children.

Instance

clone ( )

[Deprecated]
void

destroy ( )

[Deprecated]
Instance

findFirstChild ( string name , bool recursive )

[Deprecated]
Objects

getChildren ( )

[Deprecated]
bool

isA ( string className )

[Deprecated] [CustomLuaState]
bool

isDescendantOf ( Instance ancestor )

[Deprecated]
void

remove ( )

[Deprecated]

Events

Inherited from GuiObject: Show Hide

RBXScriptSignal

DragBegin ( UDim2 initialPosition )

[Deprecated]

Fired when a player begins dragging the object

RBXScriptSignal

DragStopped ( int x , int y )

[Deprecated]

Fired when a player stops dragging the object

RBXScriptSignal

InputBegan ( Instance input )

Fired when a user begins interacting via a Human-Computer Interface device (Mouse button down, touch begin, keyboard button down, etc)

RBXScriptSignal

InputChanged ( Instance 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)

RBXScriptSignal

InputEnded ( Instance input )

Fired when a user stops interacting via a Human-Computer Interface device (Mouse button down, touch begin, keyboard button down, etc)

RBXScriptSignal

MouseEnter ( int x , int y )

Fires when a user moves their mouse into a GUI element

RBXScriptSignal

MouseLeave ( int x , int y )

Fires when a user moves their mouse out of a GUI element

RBXScriptSignal

MouseMoved ( int x , int y )

Fires whenever a user moves their mouse while it is inside a GUI element

RBXScriptSignal

MouseWheelBackward ( int x , int y )

Fires when a user scrolls their mouse wheel back when the mouse is over a GUI element

RBXScriptSignal

MouseWheelForward ( int x , int y )

Fires when a user scrolls their mouse wheel forward when the mouse is over a GUI element

RBXScriptSignal

SelectionGained ( )

Fired when the GuiObject is being focused on with the Gamepad selector

RBXScriptSignal

SelectionLost ( )

Fired when the Gamepad selector stops focusing on the GuiObject

RBXScriptSignal

TouchLongPress ( Array touchPositions , UserInputState state )

Fires when the player starts, continues and stops long-pressing the UI element

RBXScriptSignal

TouchPan ( Array touchPositions , Vector2 totalTranslation , Vector2 velocity , UserInputState state )

Fires when the player moves their finger on the UI element

RBXScriptSignal

TouchPinch ( Array touchPositions , float scale , float velocity , UserInputState state )

Fires when the player performs a pinch or pull gesture using two fingers on the UI element

RBXScriptSignal

TouchRotate ( Array touchPositions , float rotation , float velocity , UserInputState state )

Fires when the player performs a rotation gesture using two fingers on the UI element

RBXScriptSignal

TouchSwipe ( SwipeDirection swipeDirection , int numberOfTouches )

Fires when the player performs a swipe gesture on the UI element

RBXScriptSignal

TouchTap ( Array touchPositions )

Fires when the player performs a tap gesture on the UI element

Inherited from Instance: Show Hide

RBXScriptSignal

AncestryChanged ( Instance child , Instance parent )

Fires when the Instance/Parent property of the object or one of its ancestors is changed.

RBXScriptSignal

AttributeChanged ( string attribute )

RBXScriptSignal

Changed ( string property )

Fired immediately after a property of an object changes.

RBXScriptSignal

ChildAdded ( Instance child )

Fires when an object is parented to this Instance.

RBXScriptSignal

ChildRemoved ( Instance child )

Fires when a child is removed from this Instance.

RBXScriptSignal

DescendantAdded ( Instance descendant )

Fires when a descendant is added to the Instance

RBXScriptSignal

DescendantRemoving ( Instance descendant )

Fires immediately before a descendant of the Instance is removed.

RBXScriptSignal

childAdded ( Instance child )

[Deprecated]

Code Samples


Countdown Text

This code sample makes a TextLabel or TextButton count backwards from 10, setting the text color as it does so.

-- 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, .5, .5) -- red
local colorDone = Color3.new(.5, 1, .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
		wait(1)
	end
	textLabel.Text = "GO!"
	textLabel.TextColor3 = colorDone
	wait(2)
end

Game State Text

This code sample mirrors the contents of a StringValue into a TextLabel, updating and setting the color of the text as it changes.

-- Place a StringValue called "GameState" in the ReplicatedStorage
local vGameState = game.ReplicatedStorage:WaitForChild("GameState")
-- Place this code in a TextLabel
local textLabel = script.Parent

-- Some colors we'll use with TextColor3
local colorNormal = Color3.new(0, 0, 0) -- black
local colorCountdown = Color3.new(1, .5, 0) -- orange
local colorRound = Color3.new(.25, .25, 1) -- blue

-- We'll run this function to update the TextLabel as the state of the
-- game changes.
local function update()
	-- Update the text
	textLabel.Text = "State: " .. vGameState.Value
	-- Set the color of the text based on the current game state
	if vGameState.Value == "Countdown" then
		textLabel.TextColor3 = colorCountdown
	elseif vGameState.Value == "Round" then
		textLabel.TextColor3 = colorRound
	else
		textLabel.TextColor3 = colorNormal
	end
end

-- Pattern: update once when we start and also when vGameState changes
-- We should always see the most updated GameState.
update()
vGameState.Changed:Connect(update)