Syntax highlighter being weird

I used the code from this post.
I’m not sure how to explain it, so here’s a video:

Code:

editor:GetPropertyChangedSignal("Text"):Connect(function()
	local syntax = editor.Text
	shower.Text = syntax
	for _, v in pairs({"int", "local", "for", "in", "do"}) do
		syntax = syntax:gsub("(%W?)(".. v.. ")(%W?)", function(l, str, r)
			return l..highlight(str, "#859900")..r
		end)
	end
	editor.Text = syntax
end)

It’s probably because you are changing the TextBox’s text when its Text changes, and that makes a loop.

1 Like

Then how could I fix that?
characters

You could use .FocusLost instead of :GetPropertyChangedSignal(“Text”)

Usually syntax highlighters have one TextBox on top that the player actually types in (but for which the text is invisible) and another text label behind that has all the colors. That way you can listen for text changes on the former while changing the text on the latter.