Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do you use FilterStringForPlayerAsync for custom chat?

Asked by 9 years ago

I have been trying to figure it out but I have not had any luck.

Please explain game.Chat:FilterStringForPlayerAsync()

http://wiki.roblox.com/index.php?title=API:Class/Chat/FilterStringForPlayerAsync

1 answer

Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
9 years ago

Well, the method is easy to understand once you've tried it once.

It's requiring two parts in its method, a string to convert and a player instance.

Say I were to make a script popup a message or something when you chat. I would use the chatted event (if you're using a custom chat bar opposed to ROBLOX's, you will need to make your own means of connecting from the client to the server) to get the string. Since PlayerAdded and Chatted events can provide me with both the string and player instance, I will use those in this example.

For this example, you will have to assume that I am using 'Test' as a curse word. The reason being is profane language has no place on this site or on the Roblox site.

game.Players.PlayerAdded:connect(function(plr) --We're getting the player at this time.
    plr.Chatted:connect(function(chat) --If the player says something, then this event will fire.
        --Now since I plan to make a message pop up (and I am not going to go full blow on the chat gui)
        --I will want to make a new Message.
        local message = Instance.new("Message",workspace) --'workspace' will make the message show up in workspace.
        --Now, we will want to edit the text property of the message, to make it show up. But we want to use Roblox's filter.
        --So, we will create a new tag, and that will be used for the text.
        --Since the 'chat' tag should have what we said, that will be the first argument in the method.
        --And since the player is saying it, let's just hope they are being appropriate, and use them for the second argument. The second argument is what determines if the script should use the White List Filter or the Black List Filter.
        local filteredmessage = game.Chat:FilterStringForPlayerAsync(chat, plr) --This means, that the script will filter 'chat' according to the 'plr''s age restrictions or permissions.
        message.Text = filteredmessage --This will change the text that appears to the filtered message.
        game.Debris:AddItem(message,5) --This is just for clean up, should destroy the message after five seconds.
    end)
end)

So, when you go to test this, say I were to say the following;

Hello, how is the test going?

If ROBLOX's filters are working properly, then the chat would say;

Hello, how is the #### going?

Once again, profanity is not allowed on this site, so you'll just have to imagine test being a curse word.


Here are some restrictions that I have noticed from experience.

  • Long strings of text, might return a 500 (or 502, not sure which) server error.
  • The function can not be used in local scripts, they can only be used in server side scripts.
0
where do i put this script carjay7 0 — 7y
0
You don't put it anywhere. The function is deprecated. Should not be used in new works. M39a9am3R 3210 — 7y
Ad

Answer this question