How to change color of a group of letters through its index in a textbox

Hello, I am trying to make it that after you type in a certain keyword in a textbox, that keyword turns a different color than the rest of the text.

How would I do this?

1 Like

You can use Rich Text

1 Like

So basically I would get where the keyword starts, add the beginning html there, then add the ending html where it ends?

Yeah, that should work. Let me know if you have any issues.

1 Like

But what im currently trying to figure out is how to remove the html from that position when part of the keyword is deleted

You could save the text as a variable and whenever they change the content of the textbox you could set the text back to the original text and add the html

1 Like
local frame = script.Parent
local label = frame:WaitForChild("TextLabel")
local box = frame:WaitForChild("TextBox")

local text = "the quick brown fox jumps over the lazy dog."

label.Text = text

	label.Text = text
	local term = box.Text
	if term ~= "" then
		local split = text:split(term)
		if #split - 1 > 0 then
			label.Text = table.concat(split, "<font color=\"#00ff00\">"..term.."</font>")

I tried doing it myself, and this seemed to work. Good luck!


Thanks so much! I’m making a script editor so that people can learn Lua and I want it to function the same way as a normal script editor would. This helps a lot!

1 Like

Sorry to bump a solved topic, but… This completely freezes Roblox Studio. Am i doing something wrong?