Changing size of the Frame, depending on letters

Hello Everyone,

I am making my own “console-admin system”, but I have a problem. I was making a function, which creates a new log, which is added into the gui and I wanted to implement a system, which would change the size of the log depending on the number of characters (letters).


(code sample below) It doesn't work.


I tried to change some values and print, but print didn't work either.

Code Sample:

newLogClone.Size.Y = tonumber(#newLogClone.Text.Text/10000+0.01)..", 0"
logsamount.Value = logsamount.Value + 1
newLogClone.Name = tostring(logsamount.Value)
newLogClone.Parent = logsframe

Console:

Frame (transparency changed to 0.8 for it to be visible, normally it’s 1) + textlabel:


Thanks for reading.

Sincerely,
MaximusL2015

I think you’re looking for TextService, GetTextSize()

https://developer.roblox.com/en-us/api-reference/class/TextService/index.html
“The TextService:GetTextSize function gives developers the ability to calculate the space required for a specific text string with specified formatting, returning a Vector2 pixel size.”

Can you please send me an example of how to use it? I am a bit confused.

The reason why it errors is because you can’t change a single component of a UDim2. You need to change the Size property altogether, like this:

newLogClone.Size = UDim2.new(newLogClone.Size.X.Scale, newLogClone.Size.X.Offset, tonumber(#newLogClone.Text.Text/10000+0.01), 0)

Though I’d rather recommend you to use a UILayout such as UIListLayout which automatically aligns gui elements for you and has a convenient AbsoluteContentSize property, which allows you to get the minimum size required for the elements to fit.

I am using UIListLayout and the text label is parented to a frame, which is copied every time, when a new log is added.

If that’s the case then you should be able to do something like this upon adding a new element to the frame with UIListLayout:

frame.Size = UDim2.new(scaleX, offsetX, scaleY, layout.AbsoluteContentSize.Y)

(obviously replace the first 3 values with your numbers/variables)

GetTextSize has four parameters. The actual text, the font size, the font itself, and the max size you want the frame to be.

GetTextSize(“Hello!”, 14, yourfonthere, Vector2.new(1000,30))

In this case, 30 pixels will be the max height of the frame.

It might be a problem because you are sending a string to an IntValue inside properties. Make sure to change your size-changing method of Y to:

newLogClone.Size.Y = tonumber(#newLogClone.Text.Text/10000+0.01 .. .0)