Is there a way to find a string but check if it found the string?

So i want my antiswear to find swears better and i want to make it find a swear word everytime a player chats everything. However, my antiswear only checks if the word is a single swear. So if you say something like “lololo (swear word) lololo” it will not censor, but “(swear word)” will censor.

And String.find only returns numbers, so i think it wouldn’t be possible to put an if statement to it. Is there any way i can find string like that? (also, i want it to blacklist multiple swears, not just one)


local sweartable = {
    
    ["Faggot"] = "Gentleman",
    ["Dipshit"] = "Smarty",
    ["Cunt"] = "Bro",
    ["Fuck"] = "Love"
}

local function switchthoseword(string)

    local sentence = string

    for k,v in pairs(sweartable) do
        local sentence = sentence:gsub(string, k, v)
    end

end

Dunno how well this is but it’s something :confused:

I dont even know where do i have to put my function to censor. I also don’t want to make it swap words.

Create a hook for player chat, etc etc etc. If you don’t know how to do this, you shouldn’t be doing this. Go learn how to program first, it will make your life so much easier.

I have a complete antiswear. The problem is it will censor a single swear word, but it won’t censor it when the message includes a swear word (ex. “#% you" won't censor, but single "#!*” will censor.)

So you want to censor the whole message rather than just the one word? Why?
FYI, contact the guy who made it. Or post the addon.

I mean, the swear word slips easily when i cover it up with other text.
And i am the guy who made it. (here is the code)

Server (i censored the bad words)


hook.Add( "PlayerSay", "censor", function( ply, text, public )
	text = string.lower( text ) -- Make the chat message entirely lowercase
	if ( text == "(insert swear word)" or text == "(insert swear word)" or text == "(insert swear word)" or text == "(insert swear word)" or text == "(insert swear word)" or text == "(insert swear word)" or text == "(insert swear word)" or text == "(insert swear word)" or text == "(insert swear word)" or text == "(insert swear word)" ) 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 )

I would make a table of all words you want to filter and then split the string on every space then finally iterate through the table of words to see if any of them match. Something like this


local badwords = {
	["fuck"] = true,
	["shit"] = true,
	["bitch"] = true
}

hook.Add( "PlayerSay", "nocursingallowed", function( ply, text, team )
	
	local split = string.Explode(" ", text)
	
	for k,v in ipairs(split) do

		if badwords[string.lower(v)] then
			ply:Kill()
			net.Start( "myMessage" )
			net.WriteEntity( ply )
			net.Broadcast()
			return ""
		end
		
	end
end )

If you wanted to replace the words you could just set the true values in the table to what they would be replaced with and then when iterating, check to see if it does not equal nil. Then where a bad word occurs just set that index to the filtered word and return a concatenation of the table

Lol, an overcomplicated verison of mine.

Wont work.

Whats the problem with swearing? All an antiswear will do is make players leave your server.

Keep to the topic bro. The why doesn’t matter, it’s the how. And he wants to know how to make a crappy addon that will kill his server population. Let him. We are here to help.

Well, i am kinda late. But i wanted to make this addon to learn.