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

Change Text Style using Code

Change Text Style using Code

Jun 23 2018, 2:02 AM PST

Problem

You want to change the style of the text of a TextLabel.

Solution

Use several style properties of the TextLabel.

local screen, text = Instance.new('ScreenGui'), Instance.new('TextLabel')
 
screen.Parent = game.StarterGui
text.Parent = screen
 
text.Text = 'Hello world'
text.Position = UDim2.new(.375, 0, .375, 0)
text.Size = UDim2.new(.25, 0, .25, 0)
text.Font = 'Arial'
text.FontSize = 'Size36'

Discussion

The first thing we did was center the text. We took ½ and subtracted it by ½ of the width and height so ½ - ¼ * ½ = ⅜ or .375. So we set the position to be a UDim2 with both scale components to be ⅜ and the Size to be ¼. Now, what does Size do in a TextLabel? Isn’t a TextLabel just text? Size will create a rectangle around your text. There are many properties that control the attributes of this rectangle, but those will be discussed later on.

The next thing we did we set the font to be “Arial”. There are 3 options in which you can set Font to be, Arial, Legacy, and ArialBold. We then set FontSize to be “Size36”. These are the sizes available to you, Size8, Size9, Size10, Size11, Size12, Size14, Size18, Size24, Size36, and Size48.

Tags:
  • text
  • font
  • gui