How can I keep the text size the same, when adding more characters?

So, I’ve been creating a custom chat, and everything works fine. But, the text doesn’t stay the same.

Whenever someone tries to write a full sentence, the text goes smaller and smaller and it get’s hard to read.

Example

I’ve tried TextService:GetTextSize() and formatting it that way, but I keep getting the same error.

10:10:13.941 - Unable to cast token to int

This is the script I’ve been trying to work on.

local events = game:GetService("ReplicatedStorage"):WaitForChild("EventsFunctions")
local chatEvent = events:FindFirstChild("ChatEvent")
local textService = game:GetService("TextService")
local contextType = Enum.TextFilterContext.PublicChat

chatEvent.OnClientEvent:Connect(function(player,msg)
	local nameTeplate = game:GetService("ReplicatedStorage"):WaitForChild("NameTemplate"):Clone()
	
	nameTeplate.Parent = script.Parent.MessageHolder
	nameTeplate.Name = player.Name
	
	local newSize = textService:GetTextSize(msg,Enum.FontSize.Size14,Enum.Font.SourceSansLight,script.Parent.MessageHolder.AbsoluteSize) --// Error Occurs Here
	
	print(newSize)
end)

This is how I have my TextLabel and TextBox setup.

Setup (TextBox)

Setup (TextLabel)

Everything else works fine, I’m just not sure how to use :GetTextSize() properly and using that, keeping the same text size for larger amounts of characters.

Any help would be appreciated!

You can add a UITextSizeConstraint that makes a limit for biggest and smallest size the text can have. If I were you I would tick TextScaled on and put UITextSizeConstraint. But it is up to you if you need that propertie.

This sort of worked? It kept the text the same size, but when it was too much, the text just disappears.

Example

I put the TextConstraint inside of the TextLabel and the TextLabel has TextWrapped.

You can make the TextBox larger on the Y Coordinate.
Or you can also make the TextBox TextScaled, but it will make the Text smaller and look all squeezed up together.
This might mess up your UI but I think it’s the only solution.

Yeah, I just had to increase the size and use the text constraints to limit the text size. Thanks!

1 Like