This code just does not work, unsure why?

I wrote this code for a simple input-output UI I am making, and visually it seems stable but I am unsure why it isn’t.

local TextBox = script.Parent
local Words = {
	["local"] = [[<font color="#FFD700">local</font>]],
	["while"] = [[<font color="#006994">while</font>]],
	["function"] = [[<font color="#006994">function</font>]],
	["do"] = [[<font color="#006994">do</font>]],
	["end"] = [[<font color="#006994">end</font>]],
	["if"] = [[<font color="#006994">if</font>]],
	["then"] = [[<font color="#006994">then</font>]],
	["not"] = [[<font color="#006994">not</font>]],
	["and"] = [[<font color="#006994">and</font>]],
	["or"] = [[<font color="#006994">or</font>]],
	["else"] = [[<font color="#006994">else</font>]],
	["for"] = [[<font color="#006994">for</font>]]

	for u,b in pairs(Words) do
		TextBox.Parent.BackGLabel.Text = string.gsub(TextBox.Text, u, b)

Any help appreciated.


What is the error/problem here? I assume you don’t have RichText property turned on.


Don’t you want to be updating the textbox’s text itself?

Alright, so your issue is likely occuring because certain strings you’re searching for are contained within other strings, i.e; “or” and “for”, you will also run into problems with variables which contain these words.

1 Like

The issue here is that the script returns no errors, but the design just does not work, refer to this image:

The intended design is, you type code and the script adds color like in ROBLOX studio or any IDE, but nothing changes.