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

How can I determine the height of GUI needed to fit wrapped text in a TextLabel?

Asked by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
9 years ago

I've tried to solve this problem many times with no success. I have a TextLabel with a long paragraph of information on it. I want it to be a certain width and have the text fit inside the label. I thought this could easily be done with a repeat loop, but instead of stopping where the text should fit it continues infinitely. Here is the code I tried:

local textLabel = script.Parent.TextLabel

local height = 0
repeat
    height = height + textLabel.TextSize
    textLabel.Size = UDim2.new(0, 100, 0, height)
    wait() -- Shouldn't be needed :(
until textLabel.TextFits

For some reason, no matter how tall the GUI gets, it never fits. Is there any other way I could work around this?

Answer this question