Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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

0
I'll have to give it a try MrCatDoggo 213 — 4y
Ad

Answer this question