How do I use TextService to filter text

I am using TextService to use as a filter for my radio, although I am not sure how to use it.

The radio works by the client sending what it said by an event and then the server script sends all the clients the message. I am filtering the chat in the server. How can I solve this issue?

Before I used some other code to filter it looked like this:

local function filterMessage(text, id)
    local filteredMessage
    local success, errorMessage = pcall(function()
        filteredMessage = TextService:FilterStringAsync(text, id)
    end)
    if not success then
        warn("Error filtering text:", text, ":", errorMessage)
        return
    end
    
    return filteredMessage
end

It always returned nil so my friend said to do this:

local function filterMessage(text, id)
	local textFilterResult = " "
	local filteredMessage = " "
	local success, errorMessage = pcall(function()
		textFilterResult = TextService:FilterStringAsync(text, id)
		filteredMessage = textFilterResult:GetChatForUserAsync(id)
		--print("Filtered text: "..filteredMessage)
	end)
	if not success then
		warn("Error filtering text:",tostring(text), ":", errorMessage)
		return
	end
	
	return filteredMessage
end

But that did nothing and still let the message go by.

make sure to test in game not in roblox studio.

I am testing on the main game that is published.

Here is more proof:

image

maybe the number wasn’t supposed to get filtered?
try to type other stuff.

I did type slurs and the filter didn’t work.

are you sure that you’re calling the function in your script?

Okay I managed to fix it. In the code I was sending the wrong data.

You should mark your reply as the solution