How to get textsize before setting size of label?

I want to get the size of the text, and thus size the label to be the correct sizing, however, :GetTextSize() requires the TextLabels size beforehand. So how else can I do this?

TextLabel.Size = -- However long the text is gonna be

I’m confused? Are you using a set size for the text, or are you enabling the TextScaled property?

Also TextLabel.Size is a font size, which is relative to the vertical size of the TextLabel.

Can you explain what you’re trying to accomplish?

I want the TextLabels size to be the exact size the Text itself would take up

Also, it’s a UDim2, not a font size

I apologize, I am used to using various different languages with different syntax and recalled roblox’s syntax inaccurately.

Anyways, are you trying to set the width or the height of the frame? And are you using TextScaled or not?

If you don’t have any constraints to what size it can be, use (0,0), since it won’t clip the size at all.

2 Likes

Hello!
To get the text size of a textlabel, you can use TextBounds property. For example:

local text_size = TextLabel.TextBounds
TextLabel.Size = UDim2.new(0, text_size.X, 0, text_size.Y)

1 Like

A textlabel set to 0,0,0,0 wont show the text, even if TextWrapped is false

That didn’t size it at all

CurrentHover = Hover:Clone()
CurrentHover.Name = Button.Name
CurrentHover.Text = Button.Name
CurrentHover.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
CurrentHover.Size = UDim2.new(0, CurrentHover.TextBounds.X, 0, CurrentHover.TextBounds.Y)

CurrentHover.Parent = HUD

It doesn’t work because TextBounds won’t update while the GuiObject is parented to nil. Just revert the order of the two last lines (first set the parent and then the size).

I meant passing that as an argument to GetTextSize, not actually making your TextLabel that size.

2 Likes