How can I detect if a string was filtered or not?

So I have a nickname filter which I am using:
function game.ReplicatedStorage.Remotes.CheckString.OnServerInvoke(player, text)

local textresualt
local FilteredString = TextService:FilterStringAsync(text,player.UserId):GetNonChatStringForBroadcastAsync()
print(FilteredString)
end

It works, but it doesn’t tell you if the string was filtered or not. I want it to return a boolean value that shows if it was filtered or not, so I can tell the player that the name should be changed because it will be hashtags otherwise.

1 Like

The Developer Hub has a great article on this…

It uses a pcall to handle all errors…

I solved it myself, just made it check if it was the same as the original string or not.

2 Likes

That won’t always work…

It can be filtered yet still be the same message. If I say Hello, I doubt very much it’d call it inappropriate and censor it… So the filtered version and the original message can potentially be the same message.

I checked, for example, if I do something like “oder” then the message will be “####” which is not the same. But if I did “hi” it would return “hi” which is the same.

1 Like

Exactly… If it fails that means that a potentially inappropriate message will be unfiltered. And with this method, you won’t be able to tell if it fails or not… The are hooked to Web Calls so they fail quite often… This can lead to your game getting moderated…

What does that mean. So FilterStringAsync failing would be roblox’s fault, not mine?

Yes but you need to handle the error and not continue with the original string. Either return that the request failed or retry a certain amount of times.

This is an example from the page of something that would help you.

local TextService = game:GetService("TextService")
local filteredText = ""
local success, errorMessage = pcall(function()
filteredTextResult = TextService:FilterStringAsync(text, fromPlayerId)
end)
if not success then
warn("Error filtering text:", text, ":", errorMessage)
-- Put code here to handle filter failure
end
5 Likes

Alright I did that. Thank you for telling me about this, it might’ve saved my game from moderation :laughing:

1 Like