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

How do I make a GUI scale with the text inside it?

Asked by
P100D 590 Moderation Voter
8 years ago

I need a GUI to become larger if it contains more text. I know about the TextScaled property, but it only resizes the text within the GUI, not the GUI itself. Just making the GUI huge won't work for me either, because I need to line up a second GUI under the first. How can I make the GUI become taller or shorter as the text inside it changes?

1 answer

Log in to vote
1
Answered by 8 years ago

There is a way, but it's kinda complicated, to do it:

1. Set the text's X alignment to left, and it's Y alignment to right.

2. Set the TextLabel's size so it fits one 'line' of text.

3. Do the following code, inside the same parent as the TextLabel.

local text = script.Parent.TextLabel -- what you resize
local maxLength = 5 -- how many characters can fit in one 'line'
local num = 0
local len = string.len(text.Text)

while len > maxLength do
    len = len - maxLength
    num = num + 1
    if len > 0 and len < maxLength then
        num = num + 1
    end
    wait()
end

text.Size = UDim2.new(text.Size.X.Scale,text.Size.X.Offset,text.Size.Y.Scale*num,text.Size.Y.Offset*num) -- resizes it, with the formula of 'size*number' making it the right size

Note, this isn't tested, so if there is something wrong, tell me. If you need more help, please ask in the comments.

Hope I helped :)

~TDP

0
Thanks! P100D 590 — 8y
Ad

Answer this question