Hey! How would I automatically scale a textlabel in a scaled billboardgui depending on the text?

Hey! I’m trying to spice up my nametags by adding the player’s level next to it and make the X scale of the textlabel automatically scale. I’ve tried a few things but they just dont scale when I zoom in/out


Im using textscaled btw

Please help if you can, thank you :slight_smile:

1 Like

What do you mean by this?

If you’re trying to scale a TextLabel from the screen itself and it doesn’t work, it’s likely that you have “Select” turned on in Home which looks like this:
image
You should turn it off by pressing 1 on your keyboard or just directly clicking Select, then reselect the textlabel. Turning select on means that you’re selecting 3D objects, not 2D UI elements.

nono i mean ingame I want its size to change depending on the name length so the text size doesnt differ. I also want it to still scale depending on zoom

You should set Automatic Size to:
X
Y
XY

thx but the sizes are scale so when I zoom out its gonna be huge

Hmm… odd. You should look for things on the DevForum similar to this.


bc look at this (nothing to resize it) but its so small

i want it to automatically scale

It’s not possible to resize it correctly, as Roblox’s game engine requires scaled text to be wrapped, or the text would look weird.
But, if you turn off TextWrapped, TextScaled will go with it.

rivals did it in some way and the level/rank perfectly aligns with it

Possibly using UIGridLayout or UIListLayout. Try out both. See how it goes.

ye i use listlayout but i need the name to scale correctly bc like the level thingy goes away if i zoom out and use any other method

Like I said, you can use UIGridLayout to possibly fix the issue.

it will limit the name size thooo


like this is so small ykyk

well i ended up finding my own fix

Want to share how, incase someone else has the same problem and finds this post?

No idea how @illusi_nz did theirs, but here’s how I would do it:

There’s a property called TextBounds which refers to the absolute size of text. Assuming that…

  • you have default text on your TextLabel and have already set up it’s size to what you expect it to be
  • the size of your TextLabel uses scale (e.g. Udim2.new(1, 0, 1, 0))

We can store defaultTextBounds and say whenever the text changes – we make a ratio between the current text’s TextBounds and defaultTextBounds. Here’s how the code would look like:

-- at the very start
local defaultTextBounds = text.TextBounds

-- whenever text changes, run this
local newToDefaultRatio = (text.TextBounds.X / defaultTextBounds.X)
text.Size = UDim2.fromScale(1 * newToDefaultRatio, 1)

1 Like

i did this

	local function updatePos()
		cl.NameInfo.Username.RankImage.Position = UDim2.new(0.485, -cl.NameInfo.Username.TextBounds.X / 2 * cl.NameInfo.Username.AbsoluteSize.Y / cl.NameInfo.Username.TextBounds.Y, 0.5, 0)
		cl.NameInfo.Username.Position = UDim2.new(.5,cl.NameInfo.Username.RankImage.AbsoluteSize.X/2,.5,0)		
	end
1 Like