How do I use TextService:FilterStringAsync()

Hello.

I am trying to find out how to FillterText. I have looked at the Dev Hub and this Post.

Can some one help me, Thanks.

Hello @Dan_foodz ,

So to use filter text, its a client based function works on local script.To try it you can do something like:

local textservice = game:GetService("TextService")
local textforfilter = "Hello this will get filtered"
local playerid = game.Players.LocalPlayer.UserId

local filteredtext = textservice:FilterStringforBroadcastAsync(textforfilter,playerid)
print(filteredtext)

Now if you want it to filter from server side you can do:

local message = "hi"
local filtered = message:FilterMessageAsync(message,fromplayerid)
print(filtered)

This function can be used on server sided scripts.

3 Likes

XD, I am trying to use it on the server, thank you for that info :smiley:

However, if you still need more assistance check this link:
Text Filtering

1 Like

Your welcome! Check the link for example scripts.

1 Like

Got it, thank you for the help!

FilterStringAsync takes 3 parameters: string to filter, the userid of the player sending, and context(private chat or not)

  • StringToFilter: pretty straight forward. What string do you want to filter?
  • FromUserId: The userid of the user wanting to filter this string. This is to apply the appropriate <13 or 13+ filter.
  • Context: Private / Public chat. What context will the string be seen in? default is private chat

FilterStringAsync returns a TextFilterResult

TextFilterResults have 3 important functions, each which returns the filtered string:

  • GetNonChatStringForBroadcastAsync(); more strict because it is meant to broadcast a text which is able to be shown to all users.
  • GetChatForUserAsync(toUserId); meant to tailor the string to a specific user. Should only be shown to the target user. Used for chat conversations only.
  • GetNonChatStringForUserAsync(toUserId) - used to filter text in a non-chat manner, such as a pets name.