How to stop a message from going through

I want to know how to stop a message from going through the chat. I did check posts from before but they were from a while ago and don’t apply to the newer TextChatService. If somebody could please help me, that would be great. Thanks for reading!

You can take advantage of the ShouldDeliverCallback callback of TextChannels to do exactly this:

--Server script inside ServerScriptService
local TextChatService = game:GetService("TextChatService")
local Channels = TextChatService:WaitForChild("TextChannels")

--the filter function(basically a filter on top of the real filter)
local function isMessageBad(message: string): boolean
	--This example wont replicate every message that contains the word "pizza"
	local badWords = {"pizza"}
	for _, word in pairs(badWords) do
		if message:lower():find(word) then return true end
	end
	return false
end

local function channelAdded(channel: TextChannel)
	if not channel:IsA("TextChannel") then return end
	channel.ShouldDeliverCallback = function(message, textSource)
		return not isMessageBad(message.Text)
	end
end

for _, channel in pairs(Channels:GetChildren()) do 
	channelAdded(channel) 
end
Channels.ChildAdded:Connect(channelAdded)

What the above code does is that based on a set of rules(in this example if the message contains the word “pizza”) it chooses to replicate the message or not. The message will appear to the client sending it, however, if it doesn’t pass the filter(in this case if they type “pizza”) it won’t replicate to other clients and they will be unable to see it. This script works on the server side so it’s not bypassable by exploiters. Also, it works in studio as well.

2 Likes

is there any way to make it not even show for the client who sent it?

1 Like