Text is not being properly cut

The text to be cut every 29 characters and wrapped to a new line, and at 250 be cut off and stopped with …
My code will not work and there aren’t any errors.

Code

messages.new = function(text : string, color : Color3, font : Font)
	local template = script.MessageTemplate:Clone()
	
	if text:len() > 31 then
		local formattedText = ""
		local maxLength = 250
		local lineLength = 29
		local textLength = math.min(#text, maxLength)

		for i = 1, textLength, lineLength do
			if i + lineLength > maxLength then
				formattedText = formattedText .. string.sub(text, i, maxLength) .. "..."
				break
			elseif i + lineLength - 1 >= textLength then
				formattedText = formattedText .. string.sub(text, i, textLength)
			else
				formattedText = formattedText .. string.sub(text, i, i + lineLength - 1) .. "\n"
			end
		end

		text = formattedText
	end



	template.Text = text
	template.TextColor3 = color
	template.Font = font

	template.Parent = script.Parent.Parent.ChatWindow
	template.LayoutOrder = #script.Parent.Parent.ChatWindow:GetChildren()
	template.Visible = true
	template.Name = text
end

I don’t think you are calling the function correctly as when I run the relevent code, it definitely splits it onto multiple lines
image

I believe the expected effect only occurs if RichText is enabled.