ChatService:FilterStringForBroadcast not filtering words

Howdy,

I’m working on a region-based chat that uses MessagingService where players are able to select their preferred region and chat with others in the same subscribed Topic. Because of the possible broad range of recipients of the message, I’m using FilterStringForBroadcast.

I tested my chat by sending some words that are a little unsavory for the nature of this site so I’ll leave them to the imagination; the end problem is that in the console/output, the filtered message will show the whole word and not have it show up as hashes.

Here is a snippet of my code:
CrossMessageService is a module that I made that uses MessagingService
ChatService is game:GetService("Chat")

PLAYER.Chatted:Connect(function(MESSAGE)
	if SENT_MESSAGES < MESSAGE_LIMIT and MUTED == false then
		local TRUE_MESSAGE = CHATSERVICE:FilterStringForBroadcast(MESSAGE,PLAYER)
		print(TRUE_MESSAGE) --I have a separate print line in the ProcessMessage function below but I added this here for clarity
		CROSSMESSAGESERVICE:ProcessMessage(PLAYER,TRUE_MESSAGE,TRUE_CHANNEL)
	else
		--print('at message limit or player has been muted')
	end
	SENT_MESSAGES = SENT_MESSAGES+1
end)
2 Likes

Have you printed the MESSAGE and TRUEMESSAGE to see if there are any differences just for testing purposes.

1 Like

Your code doesn’t look to have any issues. As for testing your system, you never clarified where you’re testing this from. Are you doing it from Studio or a live game? The filter does not process messages in Studio.

By the way: TextService and its FilterStringAsync method canonically superseded the filter methods under the Chat service. You should be using this instead.

3 Likes

That’s likely why I was having my problem; I was running this code in Studio – just tested it in a real game and it works perfectly.

Thank you for pointing me to TextService as well. Does this mean that ChatService may become deprecated in the future?

1 Like

MESSAGE and TRUEMESSAGE returned the same result. Turns out that running the code in studio won’t actually filter the sent message.

2 Likes

ChatService will continue to be supported as it has use for other functions and acts as the container and distributor of the Lua Chat System. Filtering methods from both services should still continue to be supported but canonically you should be using TextService. Arguably also has a nicer API and higher degree of configuration for context.