Anti Bad Words Script

I want to make, a script like If people say words, It auto-censors, I want it to work on my language, Russian language, It Is Russian game, and people swear on Russian, I want all bad words that they say, get censored / tagged.

I couldn’t find a script, that does what I need.
I tried using, this script:

Screenshot

https://gyazo.com/5de3f9b9d0489e7dc714e83218122969
This text will be hidden

The Script
function onChatted(msg, recipient, speaker)

local source = string.lower(speaker.Name)
	msg = string.lower(msg)

if (string.match(msg, "BAD WORD")) then
speaker.Character:remove()
end

if (string.match(msg, "BAD WORD")) then
speaker.Character:remove()
end

if (string.match(msg, "BAD WORD")) then
speaker.Character:remove()
end

if (string.match(msg, "BAD WORD")) then
speaker.Character:remove()
end

if (string.match(msg, "BAD WORD")) then
speaker.Character:remove()
end

if (string.match(msg, "BAD WORD")) then
speaker.Character:remove()
end

if (string.match(msg, "BAD WORD")) then
speaker.Character:remove()
end

if (string.match(msg, "BAD WORD")) then
speaker.Character:remove()
end

if (string.match(msg, "BAD WORD")) then
speaker.Character:remove()
end

if (string.match(msg, "BAD WORD")) then
speaker.Character:remove()
end

	if string.match(msg, "ban") then
		local players=game.Players:GetChildren()
		for i=1, #players do
			if string.match(msg, string.lower(players[i].Name)) then
					if (speaker.Character:findFirstChild("Humanoid") ~= nil) then speaker.Character.Humanoid.Health = 0 end
					return
				end
				players[i]:remove()
				return
			end
                end
	end

function onPlayerEntered(newPlayer)
	newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
	newPlayer.Changed:connect(function (property)
		if (property == "Character") then
			onPlayerRespawned(newPlayer)
		end
	end)
end

game.Players.ChildAdded:connect(onPlayerEntered)

You will need to use Roblox’s built in chat filter:

The important part is this:

local TextService = game:GetService("TextService")
local filteredText = ""
local success, errorMessage = pcall(function()
	filteredTextResult = TextService:FilterStringAsync(text, fromPlayerId)
end)
if not success then
	warn("Error filtering text:", text, ":", errorMessage)
	-- Put code here to handle filter failure
end
4 Likes

I will try It thanks! I have to put this in Server Script Service or Workspace or no need…

Textboxes aren’t automatically filtered?

Nope. You have to filter them yourselves (Use a script to do it).

It will only work on the server. If you have multiple scripts that handle userinput, it would be best to use a module that will return the filtered string. If you’re only using one script, a function would do fine.

I don’t think, so…

Where to put this, script???

Anytime you allow a user to enter string-based input, you must run that input through the filter. I would recommend you put the filter code in a module, and call it to return the censored String (return nil if the pcall fails).