Custom chat system not filtering messages

  1. What do you want to achieve? I want to make a custom chat system for my game.

  2. What is the issue? The system will not filter messages regardless of their content. I am not receiving any type of error, it just returns the raw message.

  3. What solutions have you tried so far? I have tried searching for people with similar problems but I can’t find any solutions which will work.

My Code:

receivechatmessage = game.ReplicatedStorage:WaitForChild("ReceiveChatMessage")

function SendMessage(player, text)
	local filtered = nil
	
	local success, errorMessage = pcall(function()
		filtered = textservice:FilterStringAsync(text, player.UserId, Enum.TextFilterContext.PublicChat)
	end)
	if success then
		
		for i,v in pairs(game.Players:GetPlayers()) do
			local filteredforplayer = nil
			
			local success2, errorMessage2 = pcall(function()
				filteredforplayer = textservice:FilterStringAsync(text, player.UserId, Enum.TextFilterContext.PublicChat)
			end)
			if success2 then
				
				local filteredforplayer = filtered:GetChatForUserAsync(v.UserId)
				print(filteredforplayer)
				
			else
				warn("Error filtering text:", text, ":", errorMessage2)
			end
		end
		
	else
		warn("Error filtering text:", text, ":", errorMessage)
	end
end

game.ReplicatedStorage.SendChatMessage.OnServerEvent:Connect(SendMessage)

Test this in a published game.

Text filtering APIs do not work in studio for security purposes. They just return the text.

I had this issue as well and it took me ages to find this poorly documented behavior.