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

Need help with chat filter system. Can someone help?

Hello, everyone!

I'm currently writing my own chat system, and I'm currently attempting to set up a chat filter. However, this only seems to work if there is one word involved ( that matches the accursed word. )

Any help would be much appreciated!

chatfilter = {}
chatfilter[1] = "badword"

s = "badword."

for w in string.gmatch(s, "%a+") do
if s == chatfilter[1] then
    print("This message contained inappropiate content.")
else
	print(s)
end
end

1 answer

You can use string.find(), if it returns nothing or nil then it can't find a bad word within a string.

Here's an example I've created.

local filteredWords = {"N00B","HATE"}

local plrString = "YOU SUCH A N00B LOLOL I HATE YOU LOLOLOL" --Typical hate speech

for i = 1, #filteredWords do
	if string.find(plrString, filteredWords[i]) ~= nil then
		print("Bad word located!")
	else
		print("Innocent words!")
	end
end

You can also track how many words were located by just having an integer that increases every time there's a bad word found.

2 comments

0

Just one thing: How do I get it to filter a word no matter the capitalization?

0

I think you need to use "%a" but i'm not sure how to give match a pattern.

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