Replacing Chat Text

I want to add a function that replaces certain words when typed in chat and show it as <Message Deleted> instead of what they originally typed. I have come up with something that blocks it, but I also want to implement the sub string. When I try adding string.Replace or string.gsub it, the code acts like it isn’t there. I should also note that I had help writing this code and both of us don’t know how to add it. If it is of any use, it’s for a Grand Theft Auto Online server which is basically modified perp.


	local lowerText = string.lower(Text)
	for filter, response in pairs(gaywords) do
		if (string.find(lowerText, filter)) then
			Player:ChatMessage(response)
			return ""
		end
	end

This is an script robotboy once made, to ban for bad words and replace the given word instead:



local bannedWords = {
	"fuck",
	"suck",
	"dick",
	"moron", -- DO NOT FORGET THE COMMAS!!! COMMA AFTER LAST ELEMENT IS OK IN LUA.
}
hook.Add( "PlayerSay", "blocked_words", function( ply, text, public )
	text = string.lower( text ) -- Make the chat message entirely lowercase
	
	local t = txt
	
	for id, str in pairs( bannedWords ) do -- Loop through all the banned words
		if ( string.find( text, str ) ) then -- If the text contains the banned word, do this:
			-- Ban the bad person, uncomment to make it work
			-- ply:Ban( 1440 ) ply:Kick( "Don't use bad words fag" )
		
			local s, e = string.find( text, str )
			t = string.gsub( t, string.sub(t, s,e), string.rep("*", e-s) )

			-- remember, you can't put code after return in the same scope!
			return "" -- Hide the entire message, comment this out if you want to just hide the bad words.
		end
	end
	
	return t -- Hide the bad words
end )


Have fun :3 -spoonfeeded-

[lua]return “<Message Deleted>”[/lua]
?

He doesnt want the whole message deleted, I think.

[lua]return string.Replace(text, str, “<Message Deleted>”)[/lua]
?

You should read the script I posted…



return "" -- Hide the entire message, comment this out if you want to just hide the bad words.