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

How would I convert TextBounds to UDim2.new?

Asked by 10 years ago

So I have this TextBox. I want to make it so its size is always the same as its textbounds. I think the way to do it is to convert TextBounds to UDim2, and make it so it's size is that. But TextBounds is 2 numbers, and UDim2 is 4.

--This is what I tried
local CodeBox = script.Parent
local CodeBox_Size = script.Parent.Size
local CodeBox_TextBounds = script.Parent.TextBounds

for i=0,math.huge do --infinite loop
    wait()
    CodeBox.Size = UDim2.new(CodeBox_TextBounds)
end

1 answer

Log in to vote
0
Answered by
Discern 1007 Moderation Voter
10 years ago

TextBounds are actually measured in pixels. The offset of UDim2 is also measured in pixels. You can make a UDim2 value, and then insert 0 for the Scale parts and put TextBounds in for the Offset parts.

Update: Didn't realize that you were changing the text. In that case, then you should be assigning your variable inside the loop. Here is the edited script:

--This is what I tried
local CodeBox = script.Parent

for i=0,math.huge do --infinite loop (Just wondering why is this here?????????????)
    wait()
    local CodeBox_Size = script.Parent.Size
    local CodeBox_TextBounds = script.Parent.TextBounds
    CodeBox.Size = UDim2.new(0, CodeBox_TextBounds.X, 0, CodeBox_TextBounds.Y)
end
0
When I run it, the size changes to the bounds of the text. After that, when I change the text, it still stays the same size and breaks. Vlatkovski 320 — 10y
0
Updated. Recheck on what I said. Discern 1007 — 10y
0
Still doesn't work, instead of expanding when I put in more text, it shrinks. Oh well, I guess I'll have to just use another method. Vlatkovski 320 — 10y
Ad

Answer this question