Hi everyone, quick question.
I'm basically sending out announcements in a game to all clients, but before doing so it individually matches the player's chat filtering settings.
I do this using a remote function to filter the chat in a server script, and then return the filtered text.
Here is my code?
Server Script:
local repStore = game:GetService("ReplicatedStorage")
local TextService = game:GetService("TextService")
function repStore.filterMsg.OnServerInvoke(player,msg)
local success, errorMessage = pcall(function()
return TextService:FilterStringAsync(msg, player.UserId):GetChatForUserAsync(player.UserId)
end)
if not success then
warn("Error filtering text:", msg, ":", errorMessage)
return
end
end
Local Script:
repStore.sendAnnouncement.OnClientEvent:Connect(function(msg,timer) --this is a remote event that is used for when an admin sends the announcement
msg = repStore.filterMsg:InvokeServer(msg)
print(msg)
end)
Any suggestions would be much appreciated.

2 comments
It is probably returning 'nil' because it didn't have enough time to process the filter, I am not so sure how you should go about to fix it.
During a test I put print(msg) before and after it being filtered (obviously removed the return and made it a variable) - it worked fine and filtered it properly it just doesn't make it back to the local script.