Text Labels On One Line while keeping Rich Text on

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:
image

Make the Size of the second text label {1, 0},{1, 0}
image

Now, make turn of visible for the second text label.
image

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.
image
You can see they look exactly the same.
image
Now, there’s a bit of a difference but not that much.
image
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.

4 Likes

Nice! By the way you don’t have to create a new function

turns into…

1 Like

Thanks for letting me know. I’ll change it.

1 Like

Oh and by the way, if you want you could probably provide a demonstration to show people that it works

1 Like

Alright, demonstration added! (message too short)

1 Like

Or just add UIPadding to the TextLabel?

This does not work if you want to use RichText and TextScaled together.

Why not? What happens?

Charschars