Antiswear wont work?

So, i am trying to make an antiswear which kills you and censors the swear word with “(name) said a bad word!”. The problem is, it kills you everytime you say something like lol or hello! (also censors it)

Here are the codes. (i censored the bad words)

Server


hook.Add( "PlayerSay", "censor", function( ply, text, public )
	text = string.lower( text ) -- Make the chat message entirely lowercase
	if ( text == "(the f word)" or "(insert swear word)" or "(insert swear word)" or "(insert swear word)" or "(insert swear word)" or "(swear)" or "(badword)" or "(noway)" or "(badword)" or "(aswearword)" ) then
		ply:Kill()
			net.Start( "myMessage" )
		net.WriteEntity( ply )
		net.Broadcast()
		return ""
	end
end )

Client


net.Receive( "myMessage", function( len, ply )
	local ply = net.ReadEntity()
	 chat.AddText( Color(255, 0, 0), "[ANTISWEAR] " .. ply:Nick() .. " just said a bad word!" )
end )

You need to repeat the condition for each swear. for example:

[lua]
if ( text == “(the f word)” or text == “(insert swear word)” or text == …
[/lua]

On another note, there will always be a way around swear filters, and honestly it decreases the popularity of servers.

You can use a table instead of having a huge if statement.

𝒻𝓊𝒸𝓀

swear filters really aren’t very effective, they’ll just result in people playing the system

This is a shared File type of code. So, if you add this to a file you’ll need to include it like a client side file and a server file.

But, you can always break the code up two different files… Which is messy for me.
Code:




if SERVER then
	AntiSwearMod = {}
	AntiSwearMod.Settings = {}
	// I'm using examples because I'm unaware if the facepunch administration would ban me for correctly putting the values in...
	AntiSwearMod.Censor = { -- Hello and world are censored. 
		"hello",
		"world"
	}
	
	util.AddNetworkString("AntiCensorMessage")

	hook.Add( "PlayerSay", "AntiSwearModModerator", function( ply, text, public )
		text = string.lower( text )
		for k, v in pairs(AntiSwearMod.Censor)do -- For loops are so much cleaner. :)
			if(string.match(text, v)then
				net.Start("AntiCensorMessage")
				net.Send( ply )
                                return ""
			end
		end
	end)
elseif (CLIENT)then
	net.Receive( "AntiCensorMessage", function( len, ply )
		 chat.AddText( Color(255, 0, 0), "[ANTISWEAR]: " .. ply:Nick() .. ", please don't use swear words in our server." )
	end)
end


[HR][/HR]
This will search their whole text example:
“Hello World, I am here to rude your days”
The under line would be censored.
[HR][/HR]
This is different way of doing the hook. And this simply just replaces the text.

Plus, I prefer this more than killing the player. :\



hook.Add( "PlayerSay", "AntiSwearModModerator", function( ply, text, public )
		text = string.lower( text )
		for k, v in pairs(AntiSwearMod.Censor)do -- For loops are so much cleaner. :)
			if(string.match(text, v)then
				net.Start("AntiCensorMessage")
				net.Send( ply )
				
				local censortext = "";
				for i=0, string.len(v) do
					censortext = censortext + "#";
				end
				
				text = string.Replace(text, v, censortext); -- Some roblox blocking here :P
			end
		end
		return text
	end)


snip

im dumb

At least have it as an option for users to enable/disable and remove the kill option.(We’re playing a game mode where gore/killing is already a thing. Why restrict swearing?). Similar to what LoL does, if you don’t want to see it then by all means you don’t have to.