Why is this filter not working?

What do you want to achieve? I want to achieve an additional filter script. (If it isn’t clear, I want to achieve a filter script that I can add additional things. To prevent people from saying admin. I want the message to be replaced to “Message Filtered”, but it doesn’t work. I don’t have any errors.)

What is the issue? The issue I’m encountering is the script isn’t working. In this video, I’m saying one of the blacklisted words and the message does not get replaced to Message Filtered

What solutions have you tried so far? I’ve tried to watch youtube videos, but nothing really helped! I’ve searched on the dev forums for other people if they tried to make a script like this and if they found a solution, but there were too many other topics that had the keywords I searched up.

local Blacklist = {"Hello, there!"} -- I put Hello for this test.

local function ScanForWords(msg)
	local count = 0
	for _,v in pairs(Blacklist) do
		if(string.find(msg,v) ~= nil) then
			count = count + 1
		end

		if (count > 3) then 
			print(count)
			return true
		end
	end
	return false
end

local function Run(ChatService)

	local function FilterRobuxWord(sender, messageObject, channelName)
		if(ScanForWords(string.lower(messageObject.Message))) then
			messageObject.Message = "Message Filtered"
		end
	end

	ChatService:RegisterFilterMessageFunction("makeLowercase", FilterRobuxWord)
end

return Run

Any help would be appreciated!

1 Like

ok, i think you could rewrite it like this. It works for me:



local Blacklist = {"hello"} -- make all words lowercase here
local function CheckBlacklist(Speaker,MessageObject , Channel)
	local Message = MessageObject.Message
	if table.find(Blacklist, Message:lower()) then
		MessageObject.Message = "Message Filtered"
	end
end
local function Run(CS)
	CS:RegisterFilterMessageFunction("Blacklistword", CheckBlacklist)
end
return Run

works for me.

1 Like

Okay, thank you! I will try it right now.

try the thing i put first,
also, try making the blacklisted words lowercase. Since you made the message become lowercase. So it wouldn’t detect if the thing has non-lowercase letters

1 Like

also, one thing I recommend you do is make it check if the message includes a blacklisted word. Since it can be bypassed with extra letters and stuff.

How would I do that? (Sorry, I’m not that good with filtering function codes, if possible could you like a dev forum post or a dev hub post?)

local Blacklist = {"hello"} -- make all words lowercase here
local function CheckBlacklist(Speaker,MessageObject , Channel)
	local Blacklisted = false
	local Message = MessageObject.Message
	for i,v in pairs(Blacklist) do
		if string.match(Message:lower(), v:lower()) then
			Blacklisted = true
		end
	end
		
	if  Blacklisted == true then
		MessageObject.Message = "Word blacklisted"
	end
end
local function Run(CS)
	CS:RegisterFilterMessageFunction("Blacklistword", CheckBlacklist)
end
return Run
1 Like

another thing you could do is make the chat message not send.

Thanks for the help, I’ll try both and I’ll mark the one I think helped the most as the solution!

1 Like