Log in to vote

Is there a way to make the size of a TextLabel adjust to how many lines of text there are?

Asked by 15 days ago

So I'm making a gui where things like errors, warnings, and other general info print out onto a gui so it's easier for myself to read.

However I ran into an issue, where if something copies over that spans multiple lines, it will overlap with the other lines that were made previously

This is some of the code I have for the gui right now.

local canvasX = 0
game:GetService("LogService").MessageOut:connect(function(output, messageType)
    local newLine = script.NewLine:clone()
    newLine.Position =, 5, 0, (#script.Parent.Scrolling:getChildren() * 15))
    newLine.Text = "> " ..output
    newLine.Name = tick()
    newLine.Parent = script.Parent.Scrolling
    newLine.Size =, (#output * 10), 0, 15)
    canvasX = (canvasX > (#output * 10) and canvasX or (#output * 10))
    script.Parent.Scrolling.CanvasSize =, (canvasX + 10), 0, ((#script.Parent.Scrolling:getChildren() + 1) * 15))

And this is what it looks like printing single lines, compared to when it prints a message with multiple lines.

Single Line:

Multiple Lines:

As you can see, my script will copy singular lines just fine, but when something spans multiple lines it will cause interference.

Is there any way to make the TextLabel adjust to how many lines the text spans?

Try using task.wait() to delay it a bit. T3_MasterGamer 845 — 15d

1 answer

Log in to vote
Answered by
enes223 312 Moderation Voter
15 days ago

If your TextLabel's text is wrappable and is not automatically sized you can just use the TextBounds property, it shows how much space does the current text take. Example:

local textSize = label.TextBounds
local defaultSize = label.Size
label.Size =, defaultSize.X.Offset, 0,  math.max(textSize.Y, defaultSize.Y.Offset))
This worked! However, I'm having trouble with having new line go to the bottom of the one with multiple lines. How would I be able to connect a new line to the bottom of the one that is multiple lines long? Qwerty_8339 12 — 15d
You would have to modify the way your code handles positioning of the TextLabel by looping through all the objects and adding their Y offset together loowa_yawn 281 — 15d

Answer this question