Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I let a TextLabel size automatically according to the text?

Hello, I am currently scripting a police Radio. I have come to a point, where I want to size the TextLabel automatically from the content. Any ideas? Thanks, Alex

2 answers

✓ Accepted answer

You could use TextService

TextService has a function called :GetTextSize() and it returns a Vector2 which contains an X and Y to scale your TextLabel. Make sure your TextLabel is Scaled.

local TS = game:GetService("TextService")
local message = script.Parent
local frame = script.Parent.Parent
local fontSize = Enum.FontSize.Size18
local font = Enum.Font.SourceSansLight

local newSize = TS:GetTextSize(message.Text,fontSize,font,frame.AbsoluteSize)

message.Size = UDim2.new(0,newSize.X,0,newSize.Y)

OR

You can just use TextBounds

Either or works!


Hope this helped!

In the properties of the textlabel scroll down to the text section(where you would do stuff like change what the text says or change the text color) and select the box that says "TextScaled." And done! Or in a script it would be for example:

local player = game.Players.LocalPlayer
local pguiLabel  = player.PlayerGui:WaitForChild("ScreenGui").Frame.TextLabel

pguiLabel.TextScaled = true

Please accept this answer if it helped.

5 comments

0

Sorry, but that is not what I mean. I mean that the textLabel gets multiple lines. The TextLabel comes from a clone out of RS.

0

Just like in the Roblox built-in chat.

0

TextScaled will give the text multiple lines if it is too long.

0

But in the roblox built-in chat, the text isn't scaled. The "borders" of the textLabel expands, when the text has reached a certain length.

0

You have got to make your question more specific then.

This discussion is preserved as it was. New answers, comments, and votes are closed.