Text Filtering

Applied to various sources and inputs, text filtering prevents users from seeing inappropriate language and personally identifiable information such as phone numbers. Roblox automatically filters common text outputs such as messages that have passed through in-experience text chat, but you are responsible for filtering any displayed text that you don't have explicit control over.

Filter Scenarios

Text can be gathered and/or displayed to users in a variety of scenarios, including:

  • An experience that gathers users' text input through TextBox entries, a custom GUI with buttons such as a keyboard/keypad interface, or an interactive keyboard model in the 3D space.

  • An experience that generates words from random characters and displays them to users, as there's a chance it will create inappropriate words.

  • An experience that connects to an external web server to fetch content that is displayed in-experience. Often you will not have control over the content of the external site and a third party can edit the information.

  • An experience that stores text such as users' pet names using data stores, where the stored text might include inappropriate words that should be filtered when retrieving them.

Filtering Process

TextService:FilterStringAsync() filters in-experience text by taking a string of text and the UserId of the user who created the text as input. It returns a TextFilterResult object which has two additional methods that you can call in different scenarios:

In the context of TextBox input, the following example gathers input on the FocusLost event and sends it to the server through a RemoteEvent. On the server, it is filtered first through FilterStringAsync() and then GetNonChatStringForBroadcastAsync() with the intention that the text will be displayed to all users on a server‑side object such as a SurfaceGui in the 3D world.

Filtering Text Input - Client Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local textBox = script.Parent
textBox.ClearTextOnFocus = false
textBox.PlaceholderText = "..."
textBox.TextXAlignment = Enum.TextXAlignment.Left
textBox.TextScaled = true
-- RemoteEvent to send text input to server for filtering
local inputRemoteEvent = ReplicatedStorage:FindFirstChild("InputRemoteEvent")
-- Event handler for focus lost and enter being pressed
local function onFocusLost(enterPressed, inputObject)
if enterPressed then
print("SUBMITTED:", textBox.Text)
if inputRemoteEvent then
inputRemoteEvent:FireServer(textBox.Text)
end
end
end
textBox.FocusLost:Connect(onFocusLost)
Filtering Text Input - Server Script

local TextService = game:GetService("TextService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- RemoteEvent to receive text input from client for filtering
local inputRemoteEvent = ReplicatedStorage:FindFirstChild("InputRemoteEvent")
local function getFilterResult(text, fromUserId)
local filterResult
local success, errorMessage = pcall(function()
filterResult = TextService:FilterStringAsync(text, fromUserId)
end)
if success then
return filterResult
else
warn("Error generating TextFilterResult:", errorMessage)
end
end
-- Fired when client submits input from the TextBox
local function onInputReceived(player, text)
if text ~= "" then
local filterResult = getFilterResult(text, player.UserId)
if filterResult then
local success, filteredText = pcall(function()
return filterResult:GetNonChatStringForBroadcastAsync()
end)
if success then
print("FILTERED:", filteredText)
else
warn("Error filtering text!")
end
end
end
end
inputRemoteEvent.OnServerEvent:Connect(onInputReceived)