GetTextSize not functioning properly in game on join

I made a button system which uses GetTextSize to position the text accordingly. This system works perfectly fine in studio, however when going in game the text size returned is not the same which makes the button not look correct.

I noticed that when first joining, the text size is not correct. However, when running the same function in console the correct size is returned. That means this only happens on join, which doesn’t make much sense to me. I also noticed that this does not happen all the time, sometimes the size is fine but most of the time it is incorrect.

I don’t know if sending the script will help as it’s only the GetTextSize function which is breaking, and like I said when running it in console it works perfectly fine. All I have is a LocalScript in StarterPlayerScripts which requires my module in ReplicatedStorage, then I require the function which runs TextService:GetTextSize(name, label.TextSize, label.Font, config.maxButtonSize).X translated: (TextService:GetTextSize("Trade", 14, Enum.Font.GothamMedium, Vector2.new(150, 30).X) and yes I made sure the arguments were the same, it’s just the return text size being different.

If anyone wants more info or knows why this is happening, any help would be appreciated, thanks. :smiley:

2 Likes

Ignore the last edit again, I solved the problem and figured out why it was happening (I think).

Basically, the font isn’t loaded fast enough when joining the game, I figured this out because when I found TextService:GetTextBoundsAsync it mentioned that if the font is not loaded than it will yield. It also mentioned you could load fonts with ContentProvider:PreloadAsync so I tried that and it actually worked.

The reason I made my last edit is I assumed it didn’t work because when running it, it just yielded forever so I guessed it was another bug until I read more on the documentation. I never knew any of this font stuff existed so learning about it is cool and it honestly seems like Roblox might be adding custom fonts.

Anyways, hopefully this will help someone.