What type of filter method should I use on chat?

hello, so im making a chat thing and im wondering which chat method I should use to filter the strings. does anyone know how I can do so?

Use FilterStringForBroadcast

Example code:

local chatService = game:GetService("Chat")
local textToFilter = "2105217059 lol 120912"
game.Players.PlayerAdded:Connect(function(plr)
      local newText = chatService:FilterStringForBroadcast(textToFilter, plr)
      print(newText) -- Prints ######## hashtags.
end)

NOTE: Text cant be filtered in studio! you have to join the game on roblox player.

https://developer.roblox.com/en-us/api-reference/function/TextFilterResult/GetNonChatStringForBroadcastAsync

If you’re making a custom chat actually want to use:

And have it wrapped with a pcall since it can error at any time. It will return an instance and then you need to loop through the players you’re sending it to and fetch the specific filter message for them.

This is for safe chat (and people without it) to have support

If you’re just having like a command that gets some text for like a sign, see:

https://developer.roblox.com/en-us/api-reference/function/Chat/FilterStringForBroadcast

This will just return a string that can be displayed to all users (if it doesn’t error) instead of an instance since it’s not player-specific.

Correct me if I’m wrong anyone, I’ve made like 4 custom chats and I don’t wanna keep using it if it’s wrong.

didn’t know that. thx for the info