This article on the developer hub explains this pretty well.
There is a couple of things you should also know when filtering text.
- It will not work in studio.
- Filtering may occasionally error and you should wrap the function in pcall.
- Text filtering only works on the server.
Try this function. This will return a string that is appropriate for all users.
local TextService = game:GetService("TextService")
local function filterText(fromUserId, text)
local textFilterResult = ""
local success, errorMessage = pcall(function()
textFilterResult = TextService:FilterStringAsync(text, fromUserId)
end)
if not success then
warn(errorMessage)
return "Failed to filter string..."
else
return textFilterResult:GetNonChatStringForBroadcastAsync()
end
end
You could call the function like this:
filterText(game.Players.Enomphia.UserId, "discord")
This would then return “#######” due to discord being censored.