How to make a command that changes the color of the message

I am wondering how to make a command that changes the color of the message. Like /color red hi
and it would output a red “hi”. I’ve tried things like:

local function Run(ChatService)
	
	local function colorCode(sender, messageObject, channelName)
		if string.find(messageObject.Message, "#red") then
			string.gsub(messageObject.Message, "#red", " ")
			messageObject.ExtraData = {
				ChatColor = Color3.new(255,0,0)
			}
		else if string.find(messageObject, "#blue") then
			string.gsub(messageObject.Message, "#blue", " ")
			messageObject.ExtraData = {
				ChatColor = Color3.new(0,0,255)
			}
		end
	end

	ChatService:RegisterFilterMessageFunction("colorCode", colorCode)
	end
end

return Run

But they don’t work.

1 Like