[SOLVED] Resizing a TextBox on the Y-Axis

I am trying to resize my textbox via the Y-axis based off of the text a player provides. I cannot resize via the X-axis due to the nature of my textbox, sadly. I’ve looked through the DevForum for solutions and haven’t found anything.

My Textbox

This is what is happening currently with the code attached.

My Code

This is a segment of my LocalScript.

local TextService = game:GetService("TextService")
local Input = script.Parent.TextBox2
local function updateSize()
local newSize = textService:GetTextSize(Input.Text, Input.TextSize, Input.Font, Input.AbsoluteSize) 
print(newSize.Y) -- prints 16 reguardless
Input.Size = UDim2.new(0, 220, 0, newSize.Y)
end
 
Input:GetPropertyChangedSignal("Text"):Connect(updateSize)

The problem I am having is the newSize.Y from the code is always returning 16, the size of the text.

Your help is much appreciated.

Can you try printing the Text, TextSize, Font, and AbsoluteSize properties?

Sure -

so you are trying to make the textbox bigger with more text?

Yes, exactly. (30 character limit)

Let’s see,

Input.Size = UDim2.new(Input.X.Scale, Input.X.Offset, Input.Y.Scale, newSize.Y)

or I think you could just do newsize idk

now that i think about it, you could just add a few to the y because I think the y is only gonna return the text size because thats the minimum size it’ll return

1 Like

Instead of using Input.AbsoluteSize in the call to GetTextSize(), try using Vector2.new(Input.AbsoluteSize.X, 1000) where 1000 should be a sufficiently large enough number.

I think what’s going on is that last parameter to GetTextSize() is how big the resulting text can be. Because you’re using the current size of the text box, which has a Y of 16, you’re telling GetTextSize that it can never use more than 16 pixels vertically, so it’s stretching horizontally. If you give it a much larger value, then it will stretch vertically into that space instead.

1 Like

I’ll give this a go.

EDIT: Success! Thank you so much for your help!

1 Like