So I made this chat filter. For example, if “bad word” is on the list any they say “bad word”, it will block the message. But they can easily bypass it by saying “b ad word” or “bad wor d”. I’m assuming I can fix this with string.sub()
? I just don’t know how I would do it. Any help is appreciated
You can remove spaces, periods, commas, etc and convert everything to lowercase and in your bad word list you would write your bad word as “badword” and check for that, but that is the most you can really do. Why don’t you want to use the roblox filter?
I agree with @Weldify . Roblox filter is good, but of course has it’s weaknesses. Adding an efficient chat filter looks like relatively simple, but is in fact not an easy task. A player can put different symbols into the chat between the letters. You can convert message to lower string and remove white spaces like this:
local noWhiteSpaceText = string.lower(""message here""):gsub('%s+', '')
And then remove every single punctation mark and ASCII character you can find, which would mean additional work, but this task is possible to accomplish using arrays, where you have all those symbols stored.
Alternatively, you can save individual characters in a table and compare it with a list of characters in the alphabet (different languages). Only keep ones that match and convert them back to the string.
The main drawback to this approach is that filtering would potentially have a lot of “false positives”. Removing punctation marks and keeping only letters in lower case can (not uncommonly) result in bad words being formed somewhere in the text, even if the message itself didn’t include any inappropriate or offensive words (or was at least not intended for use in a negative way).
For Example
Please forgive the words I chose! They are not inappropriate, but can be used in offensive way as an insult of player’s gaming abilities:
Suppose the string “heistrash” is in your banned words list.
Player_1 (original msg to Player_2): bruh u so bad, why dont u quit
Player_3 (original msg): don’t listen to this guy! he is “trash-talking”. you are not bad at all, just a beginner!Player_3’s message is censored, even though he is actually defending Player_2.
- It’s crap
- Children want to speak aswell
- yes
…? childrens can speak aswell. except xbox users.
Clearly you didn’t get the joke, their SAFECHAT I mean.
Thanks, I put this in my filter and now it works with messages like “bad wo rd” and "b ad word "