Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would i add a filter to my custom chat?

I need to add a filter so my game doesn't get moderated or anything.

local storage = game.Workspace.ChatStorage
local ChatService = game:GetService("Chat")

game.Players.PlayerAdded:connect(function(plr)
	wait(0.1)
	local newplayer = Instance.new("StringValue",storage)
	newplayer.Name = plr.Name.." Has joined the server!"
	plr.Chatted:connect(function(msg)
		local message = Instance.new("StringValue",storage)
		message.Name = plr.Name..": "..msg
	end)
end)

while wait(300) do
	for i,v in pairs(storage:GetChildren()) do
		v:Destroy()
	end
end

2 answers

Expanding upon the previous answer, there are two functions which are important: FilterStringAsync and FilterStringForBroadcast. They both function very similarly, but with slightly different parameters. They are both members of the Chat service.

FilterStringAsync has three parameters:

  • The first is simply the string to be filtered.
  • The second is the player who is sending the message.
  • The third is the player who is receiving the message.

However, if you don't know (or care) who the message is being sent to, as is likely the case with your chat system, you may prefer FilterStringForBroadcast. It is similar to the previous function, but with only two arguments: the string to be filtered, and the player sending the message. The idea is that the string returned by it will be acceptable for anyone to see regardless of their chat settings.

More information on these functions can be found here.

Hopefully this is what you are looking for.

Also, apologies for going a bit off-topic, but I noticed this code here:

while wait(300) do
    for i,v in pairs(storage:GetChildren()) do
        v:Destroy()
    end
end

This code looks like it could be implemented in a better way. I would suggest looking into the Debris service.

This discussion is preserved as it was. New answers, comments, and votes are closed.