How Do I filter custom chat

How do I actually filter this so that I respect age groups because theres so many methods to doing so. You can do it through the result, textchatservice, text service. So which is the current standard. I dont want to break TOS


chatRemoteEvents:FindFirstChild("SendMessage").OnServerEvent:Connect(function(player: Player, requestedMessage: string)
	local success,filteredMessage = pcall(function()
		return textService:FilterStringAsync(requestedMessage, player.UserId, Enum.TextFilterContext.PublicChat)
	end)

	if not success then 
		return
	end
	
	
end)

Here is the line of code that is correct I believe is - TextService:FilterStringAsync
But that’s what you have done there so maybe this:

local function filterMessage(fromPlayer, message)
    if typeof(fromPlayer) ~= "Instance" or not fromPlayer:IsA("Player") then
        warn("Invalid player object.")
        return ""
    end
    if typeof(message) ~= "string" then
        warn("Message must be a string.")
        return ""
    end

    local success, filteredText = pcall(function()
        local filterResult = TextService:FilterStringAsync(message, fromPlayer.UserId)
        return filterResult:GetNonChatStringForBroadcastAsync()
    end)
if success then
        return filteredText
    else
        warn("Text filtering failed:", filteredText)
        return ""
    end
end
1 Like