Trying to blacklist some words

I wanted to blacklist words in a table but it doesn’t work

What is my mistake?

local blacklist = {
	"test",
	"okay"
}

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		local chat = string.split(msg," ")
		if string.find(chat,tostring(table.find(blacklist,chat))) then
			print("action")
			plr:Kick()
		end
	end)
end)

string.split() returns a table. so try using table.find() instead of string.match().

local chat = string.split(msg, " ")

for _,word in pairs(blacklist) do
      if table.find(chat, word) then
         print("action")
         plr:Kick()
    end
end

Why not do this:

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		local lowerMsg = string.lower(msg)

		for _, v in pairs(blacklist) do
			if string.match(lowerMsg, string.lower(v)) then
				print("action")
			end
		end
	end)
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.