Make a certain word a certain color in a textbox with rich text

i want to make it so if it find the word sell in the string of text then it makes only that word blue for example. how do i do that

local text = script.Parent.inner.TextBox.Text
	if text:find(string.lower("sell")) then -- this only find the word but how do i make it make that word a certain color
		print("found")
	end

I believe something like this would work, could be new methods, idk
also I heard about a module , because I was searching for a module I found this one , no idea how good or new it is but Rich Text Markup - Roblox

local label = script.Parent
local text = "hehehehaw"


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

Basically the term is the one that gets colored

1 Like

You should lookup tutorials on ‘rich text’ in Roblox.

I want the <font color="#FFA500">orange</font> candy.

the output says
Maximum event re-entrancy depth exceeded for Instance.Changed (x786)
the instance (textlabel) was only changed once i did a .changed event for when i updated the text

Could you possibly show some of your code, it might just have a slight problem

its supposed to see if the text contains the word “selling” and if it does it makes that word a certain color

script.Parent.Changed:Connect(function() -- it changes when i update the text
	local label = script.Parent
	local text = label.Text
	local term = "selling"
	if term ~= "" then
		local split = text:split(term)
		if #split - 1 > 0 then
			local new = table.concat(split, "<font color=\"#2f38ff\">"..term.."</font>")
			label.Text = new
		end
	end
end)

use this instead, tell me if the error still occurs, I might have to test the script myself then

script.Parent:GetPropertyChangedSignal("Text"):Connect(function()
local label = script.Parent
	local text = label.Text
	local term = "selling"
	if term ~= "" then
		local split = text:split(term)
		if #split - 1 > 0 then
			local new = table.concat(split, "<font color=\"#2f38ff\">"..term.."</font>")
			label.Text = new
		end
	end
end)

3 Likes

i already tried that. it does nothing. the script never even starts to run

Well, the way this works, is when the text of the script.parent changes it runs this function.
make sure this code is in a local script inside a object that has a text property for ex, textbox or label

Screen Shot 2022-08-10 at 3.08.27 PM
it is and the text is updating/changing the script doesnt run tho

also the text doesn’t update right either. it should say "selling is coming soon"

Is rich text enabled? Double check it!

2 Likes

actually it completely works

script.Parent:GetPropertyChangedSignal("Text"):Connect(function()
local label = script.Parent
	local text = label.Text
	local term = "selling"
	if term ~= "" then
		local split = text:split(term)
		if #split - 1 > 0 then
			local new = table.concat(split, "<font color=\"#2f38ff\">"..term.."</font>")
			label.Text = new
		end
	end
end)

put rich text enabled

2 Likes

o damn i can’t believe i forgot that ya it wasnt. the first one i had it was but i made a new one for testing. thank you đŸ„č

1 Like