Filtering message from one player to everyone in a custom chat

Hello everyone !

I’m currently trying to create my own chat, as i don’t want any trouble with roblox, I want to do the text filtering of my game the right way.

After reading a bit, I understand that if player A is sending a message to player B, it must go like this :

local function getTextObject(message, fromPlayerId)
	local textObject
	local success, errorMessage = pcall(function()
		textObject = TextService:FilterStringAsync(message, fromPlayerId)
	end)
	if success then
		return textObject
	end
	return false
end
 
local function getFilteredMessage(textObject, toPlayerId)
	local filteredMessage
	local success, errorMessage = pcall(function()
		filteredMessage = textObject:GetChatForUserAsync(toPlayerId)
	end)
	if success then
		return filteredMessage
	end
	return false
end

function StringUtil.Filter(plrA, plrB, str)
	local messageObject = getTextObject(str, plrA.UserId)

	if messageObject then
		if toplayer then
			messageObject = getFilteredMessage(messageObject, plrB.UserId)
		else
			messageObject = getFilteredMessage(messageObject, plrA.UserId) <-- not sure about this; if the player send a message in the chat and everyone can see it.
		end
	end

    if not messageObject then
         messageObject = "error"
    end
	
	return messageObject
end

Do i need to use the same filter if the message is from one player to everyone ? Or is it okay to leave it like this ?

2 Likes

Not too sure you should use a custom filter in the first place… people have been terminated for that.
I’m pretty sure custom filters are against the ToS.

If you’re doing this, first run it through Roblox’s filter. Only add-ons are allowed.

Reference here (read this)

Also:

Hey, the person that I quoted is here!
And he said this:

I’m not using a custom filter, I’m making my ownchat but still using the filter roblox is offering. There is different kind of filter proposed by roblox and I don’t know which one is the best for this case.

Some filter are stronger than others, I don’t want my chat to be full of ############ and I don’t want to have problems with roblox too hhahaha.

I should clarify that passing a user’s chat message through your own filter in addition to the Roblox filter is perfectly fine. What counts is that at some point it passes through Roblox’s filter.

2 Likes

I guess i got my answer, it litteraly says “Returns the text in a properly filtered manner for all users.” :