Help with text bounds and for a chat system

I’m have been trying to get a custom message sent in chat to be offset from the name like normal roblox chat using spaces by taking the size of the name tag / the size of a single space and it almost seems to work
image

but for some reason with some fonts it stops working right and I have no idea why, basically it will sometimes not have enough enough spaces. and I think its tied to the font some how
image
image

I have looked and seen a few people with similar issues and have tried alot of the solutions others have suggested like using :GetTextSize() but no matter what I do it seems to not work right.

I have it so it gets the text bounds for the name and the size or the name decorations for it then divides that by the size of a single space in a frame

local TextSize = NameText.TextBounds.X+44
local SpaceSize = NameText.SpaceSize.TextBounds.X
local NumberOfSpaces = math.ceil(TextSize/SpaceSize)

MessageText.Text = string.rep(" ",NumberOfSpaces)..Text

certain fonts like Michroma, Cartoon, Arial, and Jura seem to have the most issues but some other fonts have problems too.

if anyone could help me out that would be awesome as I have been trying to get this working for hours.

So basically when a specific font is chosen even though the size is okay for other fonts, that font surpasses the bonds and goes over the message text, right? You could set up a table to store the space required by each font and place it between the message and the name. Are you using TextScaled?

no im not using text scaled, the size is always the same

The two solutions are either moving the message right based on the font type using a table that defines the distancing or use text scaled, this issue mainly occurs because of different fonts having different base sizes, so a 10px text of font1 won’t be the same size as 10px on font2.

well the thing is that im using a label to measure the exact size of a space. so it should work right?

wait im so dumb… i was using the name text to measure the space size for the message text but they don’t have the same text size. the name is size 22 and the message text is size 20

2 Likes

well thanks for trying to help lol im glad i finally figured it out :3

1 Like

Yeah other than something like what you said, I would dare to say that your method should be unreliable but may not be. In other words, the size of 1 space != size of the letter m. At least for a lot of fonts. Spam m and you might see overlap as well. Other than your current method, you can take the values of the text object and the new text and pass them to TS:GetTextSize() to get the x y size.

yeah now that I found out the issue I will probably try :GetTextSize() again to see if it works