How to detect if a player's message got censored

  1. What do you want to achieve?
    I want to detect if the player has chatted something that got censored.
    So pretty much get the filtered message from Player.Chatted:Connect(function(msg).

  2. What is the issue?
    I have “no idea” on how to do this, I know that there is a function to filter the message, but I’m wondering if there is a more efficient way of doing this?

  3. What solutions have you tried so far?
    There are no examples online so I couldn’t try anything.

local plr = game:GetService("Players").LocalPlayer

plr.Chatted:Connect(function(msg)
	
	--what am I suppose to do here???
	
end)

Hello El_risitas!

I am sure that you can still print their message even if it gets censored you can still see the message so you could use TextService to try and filter their message (which is just a string)

If it gets filtered that means their chat message and that way you’ll have it detected.

Don’t know how to do that? Here’s a community tutorial about this!

1 Like

Just a claimer, filtering string doesn’t work in studio (if you didn’t know) so you’d need to publish the place and test it in the game instead of studio.

1 Like

I followed the tutorial and I know it works because I used it once but now I’m getting some error called “Attemp to index boolean with ‘find’” which I understand but I dont understand why it is a boolean, I know that the script returns false if it fails but for this error to come everytime I filter a message means the Filter is simply broken.

local event = game:GetService("ReplicatedStorage"):WaitForChild("RE"):WaitForChild("Msg")

local TextService = game:GetService("TextService")

local function filterMessage(plr, msg)
	local result
	local success, err = pcall(function()
		result = TextService:FilterStringAsync(msg, plr)
	end)
	if success then
		return result
	end
	return false
end

local function getFilteredMessage(plr, msg)
	local result
	local success, err = pcall(function()
		result = msg:GetChatForUserAsync(plr)
	end)
	if success then
		return result
	end
	return false
end

event.OnServerEvent:Connect(function(plr, msg)

	local filteredMessage = filterMessage(msg, plr.UserId)
	local message = getFilteredMessage(filteredMessage, plr.UserId)
	
	if message:find("#") then --  this is the error line btw
		plr:Kick("You got censored.")
	end
end)
1 Like
local filteredString = game:GetService("Chat"):FilterStringForBroadcast(msg)

filteredString will be the filtered message

1 Like

Same error as the other script.
“Attemp to index boolean with ‘find’”

local event = game:GetService("ReplicatedStorage"):WaitForChild("RE"):WaitForChild("Msg")

event.OnServerEvent:Connect(function(plr, msg)

	local message = game:GetService("Chat"):FilterStringForBroadcast(msg)
	
	if message:find("#") then
		plr:Kick("You got censored.")
	end
end)

You should be checking if your filtering function returns true not if the message has “#” character.

The function will return true if it finds a #.

PS: I’m testing a solution right now!

1 Like

Not sure why Roblox did that, I guess I’ll experiment as well in the mean while.

On the developer forum it says that it returns a string as well which is weird.

I forgot to add the player parameter in the filtering function, but you don’t need it as you’re just checking if the message has a hasttag.

Solution:

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg:find("#") then
			print("filtered")
		end
	end)
end)

This will check if the message sent contains a hashtag.

I will look if I can find a way to actually see if the message was actually filtered, rather than looking for a hastag.

1 Like

But this will only check the message before filtering, so it can’t detect the hashtags that might come after filtering.
(Sorry, I didn’t see the last part of your message.)

Hmm you must be right, my bad. Sadly I can’t edit and test scripts on mobile so i am hoping you can take care of his issue.

1 Like

Alright, I tested it in-game and that seems to be true, so here’s the actual solution:

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if game:GetService("Chat"):FilterStringForBroadcast(msg, plr):find("#") then
			print("filtered")
		end
	end)
end)

(tested in-game, it works.)

1 Like

It does work! Thank you so much.

TextService:FilterStringAsync should only be used to filter for a specific player, hence the need for the player id. FilterStringForBroadcast filters it for general use, such as broadcasting, so you don’t need to filter for every player.