Is there a better way to maintain text scale with TextScaled on?

I couldn’t really find much on this so I decided to try and figure it out myself, I just wondered if there was a better way to do it.

Basically I want to have TextScaled on but prevent people writing so much that the text size decreases, this is for use on a chat field.

The solution I have is to use a changed listener that detects when the TextBounds Y scale changes and then replacing it with the last known “safe” string, here is that code:

As no one has offered an alternative I fixed up the code and prevented resizing breaking the code, here is that for anyone wanting a solution:

local NormalY = Input_Field.TextBounds.Y
local SafeText = nil

Input_Field:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
	NormalY = Input_Field.TextBounds.Y
end)

Input_Field:GetPropertyChangedSignal("Text"):Connect(function()
	if Input_Field.TextBounds.Y ~= NormalY then
		print("Too much text")
		Input_Field.Text = SafeText
	else
		SafeText = Input_Field.Text
	end
end)
1 Like

do you want a limit, for a text limit you would do

script.Parent.Changed:Connect(function()
	local text = script.Parent.Text
	if #text > 10 then --wtv num here
		script.Parent.TextEditable = false
	else
		script.Parent.TextEditable = true
	end
end)

Yes and no, problem with that method is this:

iiiiiiiiii
WWWWWWWWWW

Both of those equal 10, but clearly one takes way more space, meaning the one with W’s will cause the text box to scale down the text, the method I’m using doesn’t even check the text, it just checks if it’s effected the TextBounds.

The code works great, I just wondered if there was a better way to do it as the current solution breaks if you resize the window.