How would I make a chat color only affect a specific chat channel?

Hi. I’m still really new to chat syntax – I’m trying to make a modulescript where the yellowTeam chat channel will have their chat color set to yellowColor only.

The problem is that the chat color affects all chat channels, I tried using the :SaidMessage method, but It didn’t work too and the chat color didn’t get set at all. I’m not sure how i would do this, help would be appreciated.

local function chatColor(ChatService)
	local yellowTeam = ChatService:GetChannel("Yellow Team")
	local yellowColor = BrickColor.new("Bright yellow").Color
	
	ChatService.SpeakerAdded:Connect(function(playerName)
		for _, speakerName in ipairs(yellowTeam:GetSpeakerList()) do
			local speaker = ChatService:GetSpeaker(speakerName)
			speaker:SetExtraData("ChatColor", yellowColor)
		end
	end)
end

return chatColor

saidmessage:

local function chatColor(ChatService)
	local yellowTeam = "Yellow Team"
	local yellowColor = BrickColor.new("Bright yellow").Color

	ChatService.SpeakerAdded:Connect(function(playerName)
		local speaker = ChatService:GetSpeaker(playerName)

		speaker.SaidMessage:Connect(function(message, channelName)
			if channelName == yellowTeam then
				speaker:SetExtraData("ChatColor", yellowColor)
			else
				speaker:SetExtraData("ChatColor", nil)
			end
		end)
	end)
end

return chatColor

1 Like

Okay for anyone wondering in the future – The chat documentation had an example about using registerfiltermessagefunction which worked.

-- This example filters a keyword, and if successful, sets the chatColor of the message
local functionId = "greenText"
local keyword = "#green"
local chatColor = Color3.new(0, 1, 0) -- green

local function doFilter(speaker, messageObject, channelName)
	-- Check if the message contains the keyword
	local start, finish = string.find(messageObject.Message, keyword)
	if start and finish then
		-- Remove (filter) the keyword from the message, also setting the ChatColor
		messageObject.Message = string.gsub(messageObject.Message, keyword, "")
		messageObject.ExtraData.ChatColor = chatColor
	end
end

local function runChatModule(ChatService)
	ChatService:RegisterFilterMessageFunction(functionId, doFilter)
end

return runChatModule

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.