wait(5)
local textService = game:GetService("TextService")
local filterThis = "Discord is filtered right? Also 69 and 420 -- just making sure :/"
print(textService:FilterStringAsync(filterThis, 0, 1))
So that obviously doesn’t work. How do you filter text? There aren’t any tutorials and Wiki isn’t helpful in explaining how to use it
You should be using it like this: textService:FilterStringAsync(filterThis, 0, 1):GetChatForUserAsync(0) -- Insert the user ID for the player you want to see the message.
Filtering doesn’t work in Studio, so you’ll want to test it in-game, also if you’re planning to have it publicly visible for other players such as a BillboardGui, you’ll want to use FilterStringForBroadcast, but you can use FilterStringAsync if it’s between players.
Example textbox filter:
local player = game:GetService("Players").LocalPlayer
-- Place this code in a LocalScript inside a TextBox
local textBox = script.Parent
local function onFocusLost(enterPressed, inputObject)
if enterPressed then
local message = textBox.Text
local filteredMessage = game:GetService("Chat"):FilterStringForBroadcast(message, player)
textBox.Text = filteredMessage
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)
I would use RemoteEvents however for actual proper filtering (Roblox doesn’t like you using the filter on client).
TextService will filter a string three different ways and then return a TextFilterResult. You need to call a method from that object in order to get the proper string used for filtering, depending on your use case.
local TextService = game:GetService("TextService")
local FILTER_THIS = "Discord is filtered right? Also 69 and 420 -- just making sure :/"
local filterResult = TextService:FilterStringAsync(FILTER_THIS, 0, 1)
local filteredText = filterResult:GetNonChatStringForBroadcastAsync()
print(filteredText)
Filtering cannot be tested in Studio and a valid UserId must be supplied for this to work. You also should be using pcall as FilterStringAsync is a web call and is error-bound, so you need to reject sending a message or queue it if the filter is down.