Hello I am trying to make a custom filter system to censor some words but I am getting problems on how to detect a custom words using string
but I couldn’t figure out as I have read developer.roblox.com but was bit useless
here is script
script.Parent.OnServerEvent:connect(function(player,text)
if text ~= "" then
local filteredText = ""
local success, message = pcall(function()
filteredText = game.Chat:FilterStringForBroadcast(text, player)
if filteredText == "Adolf" then
filteredText = "#####"
elseif filteredText == "Adolf. H" then
filteredText = "########"
elseif filteredText == "German Leader" then
filteredText = "#########"
elseif filteredText == "Adolfe" then
filteredText = "#######"
elseif filteredText == "ADOLF. H" then
filteredText = "########"
end
end)
if success then
script.Parent.Parent.Name = filteredText
end
end
end)
I know using elseif with that way is pretty bad and easy to bypass it that is why I am here to ask for help…
I tried using string.sub and string.lower() but they are not helpful in this situation, because I want it also to detect if it is either caps or not because somebody might do it with this way to bypass it “aDoLf”
If s:upper() == s then that means s is all caps. If s:lower() == s then s is in all lowercase. For simplicity’s sake s:lower() == "adolf" is probably what you want to ignore casing but Roblox censors that name anyway and you shouldn’t assume that when they use that name they are referring to you know who.
I think he’s trying to add onto the Roblox filter, not replace it.
Anyway making a custom filter which replaces the original Roblox one is completely against the rules.
You would have to consider Special Characters and Random Spaces but also if you want to go through with this you should make a function that counts the number of characters and adds a proportional amount of tags to save some time
local bannedWords = {"adolf", "german leader"} -- banned words list
script.Parent.OnServerEvent:connect(function(player,text)
if text ~= "" then
local filteredText = ""
local success, message = pcall(function()
filteredText = game.Chat:FilterStringForBroadcast(text, player)
if table.find(bannedWords, filteredText:lower()) or
string.find(filteredText:lower(), table.unpack(bannedWords)) then
filteredText = string.rep("#", #filteredText)
end
end)
if success then
script.Parent.Parent.Name = filteredText
end
end
end)
Ok, I would say to make a loop through the banned words list and check if the filteredText contains any of the words
Example:
local list = {"string", "message"}
local wordToFilter = "message_string"
for _, word in pairs(list) do
if string.find(wordToFilter:lower(), word) then
print("filtered")
end
end
Ok so it works but doesn’t filter anything (it doesn’t even filter made by roblox) here is the code
local bannedWords = {"adolf", "german leader"} -- banned words list
script.Parent.OnServerEvent:connect(function(player,text)
if text ~= "" then
local filteredText = ""
local success, message = pcall(function()
for _, word in ipairs(bannedWords) do
if string.find(filteredText:lower(), word) then
filteredText = string.rep("#", #filteredText)
else
filteredText = game.Chat:FilterStringForBroadcast(text, player)
end
end
end)
if success then
script.Parent.Parent.Name = filteredText
end
end
end)
``