Ever made a TextLabel and turned TextScaled on, only to find out that when the text is too big it creates another line. After that, you search for a fix and all the post say to turn off Rich Text.
If you don’t want to turn it off, you have come to the right place.
This will be a quick tutorial.
So, first make the TextLabel and turn on Rich Text.
Make sure TextScaled is turned off and TextWrapped is turned off too.
After that, add a local script and another TextLabel inside of it.
Name the second text label “TextToTry”…
Should look like this:
Make the Size of the second text label {1, 0},{1, 0}
Now, make turn of visible for the second text label.
And the last thing to do is to paste this script inside of the local script you made.
local TextLabel = script.Parent
local DefaultSize = 10
local BorderOffset = 3
local TextService = game:GetService("TextService")
function OneLineSize()
local TextLabelVector2 = Vector2.new(TextLabel.AbsoluteSize.X, TextLabel.AbsoluteSize.Y)
local SizeOn10Pixels = TextService:GetTextSize(TextLabel.Text, DefaultSize, TextLabel.Font, TextLabelVector2)
local ClampSize = Vector2.new(math.clamp(SizeOn10Pixels.X, 0, (TextLabelVector2.X / 2) - BorderOffset), SizeOn10Pixels.Y)
local Percentage = TextLabelVector2.X / ClampSize.X
local Height = math.floor(math.clamp(ClampSize.Y * Percentage, 0, TextLabelVector2.Y))
TextLabel.TextToTry.Text = TextLabel.Text
TextLabel.TextToTry.TextSize = Height
if TextLabel.TextToTry.TextFits == false then
repeat
Height -= 1
TextLabel.TextToTry.TextSize = Height
until TextLabel.TextToTry.TextFits == true
TextLabel.TextSize = Height
else
TextLabel.TextSize = Height
end
end
OneLineSize()
TextLabel:GetPropertyChangedSignal("Text"):Connect(OneLineSize)
TextLabel:GetPropertyChangedSignal("Size"):Connect(OneLineSize)
Quick demonstration:
The TextLabel on the left is the one that is scripted. The one on the right has TextScaled on and Rich Text on.
You can see they look exactly the same.
Now, there’s a bit of a difference but not that much.
Here is where it starts to work.
It doesn’t create another line.
You can always change the BorderOffset value, but changing the DefaultSize value wont do anything.
If this doesn’t work please share your output in a reply.
Note: this can not be used with bold text.