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
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:
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
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.
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)