I want a text label that automatically resizes based on text length. This works, but for some reason only with the Gotham font. I want to add font changing to my module, but this has stopped me. For example:
When using the SpecialElite font, the text goes outside the text label, but the TextBounds only return the size for the Gotham font. Can someone help with this please?
It’s the max size of the frame, which is useful if you want your text to wrap after a certain size.
If you want it to always be one line, you can set the size to be huge:
local str = label.Text -- or whatever
local fontSize = label.TextSize
local font = label.Font
local size = Vector2.new(math.huge, math.huge)
local bounds = game:GetService("TextService"):GetTextSize(str, fontSize, font, size)
label.Size = UDim2.fromOffset(bounds.X, bounds.Y)
GetTextSize with a huge size is asking: “given this font, and with an infinite amount of room to expand without wrapping, how big would the text theoretically be?”
It will be accurate if the text on the label also doesn’t wrap.