Why chat commands and system messages need text filtering
Roblox doesn't filter the text after a chat command or a system message your game shows. How to filter it on the server before other players see it.
What it looks like
Player text reaches other players through parts of TextChatService that Roblox doesn't filter. A chat command such as /afk gone fishing or /title Dragon Slayer takes the words after the alias and shows them above the player's head or relays them to everyone. Or the server passes text a player wrote, such as a boat, pet or crew name, to clients that show it in the chat window with DisplaySystemMessage or in a bubble with DisplayBubble.
command.Triggered:Connect(function(textSource, message) local note = string.match(message, "^%S+%s+(.+)$") showAboveHead(textSource.UserId, note) end)
What an exploiter could do
They put slurs, abuse or personal information in front of every player in the server, in a place that looks like part of Roblox's own chat. A system message line looks like it comes from the game, which makes scams such as fake giveaways more believable. Roblox's filtering guide says a game found not to filter text is removed until filtering is added.
How to fix it
- In a command handler, take the text after the alias, check its length, and filter it on the server with
FilterStringAsyncusing the sender'sUserId, thenGetNonChatStringForBroadcastAsync()for text everyone can see. - Filter player text on the server before relaying it for a system message or bubble. Filtering on the client doesn't count, as the client that sends the text can skip it.
- Wrap both filter calls in
pcall. If filtering fails, show nothing. - Escape player text before it goes into a system message, and keep a cooldown on anything shown to everyone, as Signs and boards players can change more than once a minute describes.
Vulnerable example
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local TextChatService = game:GetService("TextChatService") local cooldown = 60 local lastShout: { [Player]: number } = {} local command = Instance.new("TextChatCommand") command.PrimaryAlias = "/bounty" command.Triggered:Connect(function(textSource: TextSource, message: string) local player = Players:GetPlayerByUserId(textSource.UserId) if not player then return end local now = os.clock() if now - (lastShout[player] or -cooldown) < cooldown then return end local reason = string.match(message, "^%S+%s+(.+)$") if not reason or #reason > 60 or utf8.len(reason) == nil then return end lastShout[player] = now ReplicatedStorage.Remotes.BountyPosted:FireAllClients(player.DisplayName, reason) end) command.Parent = TextChatService Players.PlayerRemoving:Connect(function(player) lastShout[player] = nil end)
Fixed example
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local TextChatService = game:GetService("TextChatService") local TextService = game:GetService("TextService") local cooldown = 60 local lastShout: { [Player]: number } = {} local function filterForEveryone(text: string, author: Player): string? local ok, result = pcall(function() return TextService:FilterStringAsync(text, author.UserId):GetNonChatStringForBroadcastAsync() end) if ok then return result end return nil end local command = Instance.new("TextChatCommand") command.PrimaryAlias = "/bounty" command.Triggered:Connect(function(textSource: TextSource, message: string) local player = Players:GetPlayerByUserId(textSource.UserId) if not player then return end local now = os.clock() if now - (lastShout[player] or -cooldown) < cooldown then return end local reason = string.match(message, "^%S+%s+(.+)$") if not reason or #reason > 60 or utf8.len(reason) == nil then return end lastShout[player] = now local filtered = filterForEveryone(reason, player) if filtered then ReplicatedStorage.Remotes.BountyPosted:FireAllClients(player.DisplayName, filtered) end end) command.Parent = TextChatService Players.PlayerRemoving:Connect(function(player) lastShout[player] = nil end)
The client that shows it escapes the text before building the system message:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local TextChatService = game:GetService("TextChatService") local general = TextChatService:WaitForChild("TextChannels"):WaitForChild("RBXGeneral") :: TextChannel local escapes = { ["&"] = "&", ["<"] = "<", [">"] = ">", ['"'] = """, ["'"] = "'", } local function escape(text: string): string return (string.gsub(text, "[&<>\"']", escapes)) end ReplicatedStorage.Remotes.BountyPosted.OnClientEvent:Connect(function(poster: unknown, reason: unknown) if typeof(poster) ~= "string" or typeof(reason) ~= "string" then return end general:DisplaySystemMessage(`{escape(poster)} posted a bounty: {escape(reason)}`) end)
How to spot this in your own scripts, and the cases that only look like it, are part of the Luaudit check your AI runs.