Trouble with filtering text -- Doesn't even filter

So I am currently trying to filter text from a surface gui.

filteredText = TextService:FilterStringAsync(script.Parent.Screen.Info.Text, game.Players.N43FGXL.UserId)

When I print ‘filteredText’ it is Instance. When I try setting my text to ‘filteredText’ it doesn’t work (obviously because its class is an instance).

Why is this? How do I get the filtered text?

In advance, thanks.

When I use :GetChatForUserAsync() it just doesn’t even get me filtered text, just my initial text.

1 Like

I think you want to be using the :FilterStringForBroadcast() method instead:

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

4 Likes

Does the code need to be in a Local Script?

It says it’s also deprecated.

1 Like

No. Filtering from a local script is deprecated, and you cannot verify that a client (aka exploiter) will filter their text.

Also filtering in studio does not work.

2 Likes

Through FilterStringAsync, an instance (text filter result object) is returned.

To get the filtered text do this

 
 local TextService = game:GetService("TextService")
 local object = TextService:FilterStringAsync(message, fromPlayerId)
 local filteredText = object:GetNonChatStringForBroadcastAsync()

Remember that these functions make web calls internally so it is ideal for them to be wrapped in protected calls (pcalls).

Also

and as @incapaz mentioned, filtering in Studio does not work.

1 Like