Confusion on TextService:GetTextSize() calculation

I’m attempting to make a custom chat system, but I’m running into a very weird problem with calculating the size of the player’s username to get how many spaces are required for the message.

The string " " returns a pixel size on the X of 4 pixels. The string “rokedev” returns a pixel size on the X of 9 pixels. How is this? The string “rokedev” is quite clearly more than 4-5x larger than the one space string.

I’m not sure if this is a problem with my text label settings, but I tried messing with them a little to no success.

I believe TextService:GetTextSize() only works if the string has already been visualized in a UI element. Some theories on why this is happening could be that you are using TextScaled on a template TextLabel of a certain size and that you resize after calling GetTextSize(). Another theory is that you are using TextWrapped which fits the text inside of its TextLabel.

It seems that the opposite is actually the problem. The “rokedev” is already visualized in a UI element and is incorrectly measured. When manually reading the TextBounds from the explorer, “rokedev” is 58 pixels, and 58/4 gives me 14.5, math.ceil gives me 15, and 15 spaces was the correct number of spaces.

Additionality, the TextBounds is another entire problem. When reading TextBounds from a script, it always returns zero. This is why we started using GetTextSize().

I fixed it, it was a problem with the AbsoluteSize argument of GetTextSize().

1 Like

This was posted a long time ago but do you remember how you calculated the size of the username label?