Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I scale a text label dependant on string size?

I'm currently making a custom chat for use in my game. Only problem for me is I want the players name text label and chat tag text label to scale dependant on the string.len() function. Is their any way to possibly make this happen?

1 answer

Don't use string.len, because some characters are different sizes, so we can't just assume they're all the same. Thankfully, roblox calculates these sizes for us and gives us a method to get those sizes. To get the length of a string in pixels, you use TextService:GetTextSize

Here's very roughly how you would implement this in your code:

local TextService = game:GetService("TextService")
...
local Size = TextService:GetTextSize(message,fontSize,font,chatFrameSize)
ChatMessageObject.Size = UDim2.new(0,Size.x,0,Size.y) --Sets width and height in pixels

1 comment

0

I'll have to give it a try

This discussion is preserved as it was. New answers, comments, and votes are closed.