Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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!

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

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. GlobixLP 6 — 4y
0
Just like in the Roblox built-in chat. GlobixLP 6 — 4y
0
TextScaled will give the text multiple lines if it is too long. IProgram_CPlusPlus 58 — 4y
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. GlobixLP 6 — 4y
0
You have got to make your question more specific then. IProgram_CPlusPlus 58 — 4y

Answer this question