What am I doing wrong in regards to TextService:GetTextSize?

Hello,

I’m attempting to make a name tag system for my pregame lobby and the goal is to incorporate the TextLabels size to be adjusted depending on how long a player’s username is! I went to the :GetTextSize() wiki page and attempted to make the following script work, no luck, then checked the DevForum and no luck there either. Although I was getting an error of 04:40:41.967 - AbsoluteSize is not a valid member of UDim2. Not too sure why this is happening. Also, my first time using TextService.

-- script
local tSTS = holder.name.text
local resizedText = textService:GetTextSize(tSTS, 32, Enum.Font.SourceSansSemibold, Vector2.new(tSTS.Size.AbsoluteSize.X, tSTS.Size.AbsoluteSize.Y))
print(tostring(resizedText))
holder.name.text.TextColor3 = plrNameColor
holder.name.Size = resizedText -- almost certain this is not how you would adjust the size.

The final line I am unsure if that is how you would properly resize the Frame that the TextLabel is parented to. Help would be greatly appreciated!

Thank you for your help,
* eiz_a

You should be doing (tSTS.AbsoluteSize.X, tSTS.AbsoluteSize.Y) instead since Size and AbsolutieSize are two different properties on GUObjects.

And at the final line you have to create an UDim2 value from the Vector2 value the :GetTextSize() function returns like this: holder.name.Size = UDim2.fromOffset(resizedText.X, resizedText.Y)

2 Likes