I was testing a script that forced a player to say something, but I still wanted the text to filter. After some tests, I finally got the script to work, but another problem came. The text was not filtering, despite being passed through TextService:GetNonChatStringForBroadcastAsync()
. I don’t know what I am doing wrong.
The following image contains vulgar language.
As you can see, I receive a message from the client through a remote event. The tuple arguments are: plr (the person who initiated the sudo), speakername (the person who is being sudo’d), and message (the unfiltered message sent through the client).
I then run the unfiltered message through TextService:FilterStringAsync, using plr as the person which the script will filter to, and giving a public chat context. It is run through a pcall, so any errors will be printed out, and the function will not continue. This filteredmessageinstance is then the value that the pcall will change. It then moves to a second pcall, which turns the instance into a filtered string. If that fails, it will not continue with the rest of a script, and print out an error. In this case, it passed both of those.
I then go on to identify the chatspeaker and finally make the chatspeaker say something. I use the filtered message that passed both pcalls in this case, and I add a tag to tell others it is not them talking directly. I still ended up with a swear word in the chat.
Any help on this would be greatly appreciated. Thanks!