String.gsub isn't working on a TextBox

local TableOfContents = {
	["local"] = "#f21414"
}

while wait() do
	for i, v in pairs(TableOfContents) do
		if(string.find(tostring(script.Parent.Text), i)) then
			string.gsub(tostring(script.Parent.Text), i, '<font color="'..v..'">'..i.."</font>", 1)
		end
	end
end

image

I made it print if it equals to the thing I want, it printed true, then I swapped the text with a normal string like “hello” and it still didn’t change.

1 Like

on this line youre doing nothing with the string you just used gsub on, if you want to change the text of the textbox then you should do something like this:

script.Parent.Text = string.gsub(tostring(script.Parent.Text), i, '<font color="'..v..'">'..i.."</font>", 1)

This does work, but I’m facing a new problem now, It keeps doing it multiple times instead of once.