String.upper and string.lower dont detect words like TeST or tEst

I’ve made a chat filter using string.upper and string.lower to detect what the players said, but they can easily bypass it by saying stuff like TEsT or teST. Here is my code, how do I fix this?

local player = game.Players.LocalPlayer
local filteredWords = {"test"}

player.Chatted:Connect(function(text)
    for index, word in pairs(filteredWords) do
        if text:find(word) or text == string.upper(word) or text == string.lower(word) then
            print("bad word")
        end
    end
end)

You could do

text:lower():find(word:lower())

2 Likes

You can detect if the message matches the filter words by using string.lower on the message like so:

local lowerCase = string.lower(text)

Since that message is now lowercase, you will need to make the filtering words lower case too or just write them out as all lower case. Line to lowercase all the words:

local WordLower = string.lower(word)

Now to check if they are the same you can use a simple if statement like so:

if lowerCase:find(WordLower) then

end
Full script
local player = game.Players.LocalPlayer
local filteredWords = {"test"}

player.Chatted:Connect(function(text)
    for index, word in pairs(filteredWords) do
        local lowerCase = string.lower(text)

local WordLower = string.lower(word)

if lowerCase:find(WordLower) then

end
    end
end)

2 Likes

Thanks for the reply, this worked

Thank you, this is what I’ve got now, all working

local player = game.Players.LocalPlayer
local filteredWords = {"test"}

player.Chatted:Connect(function(text)
	for index, word in pairs(filteredWords) do
		if text:find(word) or text:lower():find(word:lower()) or text:upper():find(word:upper()) then
			print("bad word")
		end
	end
end)
1 Like

I wouldn’t check both uppercase and lowercase since it is a waste. (It may even cause lower performance due to multiple checks).

1 Like

Yea, using one of them is sufficient enough as it transforms both words either lowercase or uppercase

While that I’m here I might aswell ask this question,

For example, if the word “cheese” was in filterWords1, and the player says cheese, I want it to print a random word from replaceWords1, vice versa if “orange” and “apple” are in filterWords2 then when the player says apple or orange, it will choose a random word from replaceWords2, not replaceWords1. If you have a better way of doing this that would work too, this is just what I thought of.

Example script:

local filterWords = {
	filterWords1 = {"word in here"},
	filterWords2 = {"word in here", "word in here"},
	filterWords3 = {"word in here", "word in here", "word in here"}
}

local replaceWords = {
	replaceWords1 = {"replacement word in here"}, --replacement words for filterWords1
	replaceWords2 = {"replacement word in here", "replacement word in here"}, --replacement words for filterWords2
	replaceWords3 = {"replacement word in here" "replacement word in here", "replacement word in here"} --replacement words for filterWords3
	
}

also I want to be able to add more filterWords like filterWords4 and replaceWords4

@HugeCoolboy2007 @aven_ue :slight_smile:

Never mind, I’ve found a solution! Thanks guys!!