Currently, we have FilterStringForPlayerAsync to filter messages for custom chat GUIs and such.
The problem is, the recommended usage of this method is very inefficient. Every time someone chats, we are supposed to filter the message separately for every player in the game.
My game has 20-player servers. So every time someone chats, that’s 20 external requests that would have to be made. When there’s a lot of people sending messages at once, there’s so many filtering requests being made that some of them start to outright fail. Message delivery is heavily delayed (the delay can be over a minute!) or never completed at all.
We only need 2 variations of a string: whitelist-filtered and blacklist-filtered. So why do we have to send an external filtering request for every single player?
This is why I’m requesting a new function and a new property to allow for a more efficient way of handling string filtering:
function game:GetService(“Chat”):GetFilteredStringsAsync( string stringToFilter, Player playerToFilterFor )
Returns 2 strings: WhitelistedString, BlacklistedString.
The Player argument is optional. If designated, the string will be filtered according to that player’s chat settings. (so if an under-13 player chats, both returned strings will be whitelist-filtered)
bool Player.UsesWhitelistChat
True if the player uses whitelist chat, false for blacklist chat.
Rather than making a separate request for every player in the game, you can just make 1 request to get both of the filtered strings that you need. Then you can appropriately distribute the messages to each player based on their chat settings, like such:
[code]local chat = game:GetService(“Chat”)
game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(message)
local WhitelistedString, BlacklistedString = chat:GetFilteredStringsAsync(message, player)
for _,recipient in pairs(game.Players:GetChildren()) do
if recipient.UsesWhitelistChat then
DistributeMessage(recipient, WhitelistedString)
else
DistributeMessage(recipient, BlacklistedString)
end
end
end)
end)[/code]