How would you resize text based on the text string length, but also respect the TextLabel's space?

Goal
I’m trying to find a way to have a typewriter effect that starts its writing with the text sized as if it was done typing. In other words: I want the text to not change size while typing.

Why this is a problem
The 2 main issues are that the text would need a mathematical function that takes into account the TextLabel’s size, and the theoretical TextSizing function would need to be scaled for all devices. How would you achieve this?

Below is a video that demonstrates the issue of the text changing its size during writing, instead of at the start.

I have now attempted to use the method of looking at TextFits property and reducing the TextSize until it fits, however the property doesn’t function correctly in-game???

TextFits always returns false until it hits 26 text size, even though in-game has a higher resolution, which should mean that TextFits would take less attempts thereby increasing the TextSize. However it defaults to 26 (same as in studio testing). What is happening here?

--Function to determine textSize
local function determineTextSize(text,dummyLabel)
	
	dummyLabel.TextSize = 100
	dummyLabel.Text = text
	
	while dummyLabel.TextFits == false do
		
		dummyLabel.TextSize -= 1
		
	end
	
	print(dummyLabel.TextSize)
	
	return dummyLabel.TextSize
	
end

although it doesn’t work in studio all the time either.
Something is wrong with the property “TextFits”?

image

I’m thinking of creating a new TextLabel for each letter, and then adding a UIGridlayout.
That way it will actually scale correclty and I can use textransparency.
Don’t have the energy to do it right now though, and I’m not sure if the spacing between letters will be respected.

You can look at the MaxVisibleGraphemes property of the text label. You can tween this property from 0 to the length of the string to achieve your desired effect.

1 Like