Textbox keywords in different colors

oh wait, i put it in the wrong script

nvm still doesnt work, it just goes infinitely

function convertString(stringToConvert: string, colors)
	local newString = stringToConvert
	for keyword, newColor : Color3 in pairs(colors) do


		newString = string.gsub(newString, '%f[%a]'.. keyword.. '%f[^%a]', '<font color="rgb('.. tostring(math.floor(newColor.R * 255)).. ','.. tostring(math.floor(newColor.G * 255)).. ','.. tostring(math.floor(newColor.B * 255)).. ')">'.. keyword.. '</font>')	
	end

	return newString
end

local colors = {
	['local'] = Color3.fromRGB(204, 0, 0),
	['print'] = Color3.fromRGB(0, 229, 255)
}

script.Parent:GetPropertyChangedSignal("Text"):Connect(function()
	local stringToConvert = script.Parent.Text
	local newString = convertString(stringToConvert, colors)
	script.Parent.Text = newString
end)

You would have to use a hex value instead of rgb and here is the correct format which I use along with rich text:

"<font color='#00FF00'>0</font>"

the zero inbetween the two arrows is the text and the quoted part with the hashtag before it is the hex. I don’t know how to get hexes without ColorHexa which is a color converter. Just enter the rgb number and it will give a hex value. Hope this helps!

that shouldnt matter if its just a color

have you found any fix for it yet?
@Mortai_Yt

I use this whenever I need to highlight Luau code in game.

im not really sure, don’t have too much time rn I might respond later though.

You’d want to enable RichText and go from there.

Click here to read about how to use rich text

1 Like