Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How should I go about using FilterStringAsync?

So basically I am making a text box that when you enter something in the text box it'll copy the text entered into the text box into a text label. But I've heard that you need to use ROBLOX's function FilterStringAsync in order to filter your texts so your game doesn't get taken down. I've looked at many tutorials, none are helping. Here is my script:

local plr = game.Players.LocalPlayer

while true do
	script.Parent.Text = plr.PlayerGui.IntroP2.introp2fr.ChannelBox.Text:FilterStringForBroadcast()
end

2 comments

0

FilterStringForBroadcast isn't a valid function of the Text property, it's a function of ChatService. If you want to filter text, you're going to have to call FilterStringForBroadcast on the server, since it's deprecated in local scripts. You're also going to have to use a RemoteFunction to return the text filtered.

0

Use it on the server, and it's game:GetService("Chat"):FilterStringForBroadcast(stringToFilter, playerFrom).

1 answer

✓ Accepted answer

###As previously mentioned, it isn't a valid function of a string. Neither can you filter on the client, as the client can disagree to filter the text, thus any malicious text being broadcasted (such as not filtering the name of a pet). You could return some filtered text from the server and have the client get that text, with a RemoteFunction.

-- Script, in ServerScriptService
wait()
local ChatService = game:GetService("Chat")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FilterText = ReplicatedStorage:WaitForChild("FilterText")

FilterText.OnServerInvoke = function(player, text)
    return ChatService:FilterStringForBroadcast(text, player)
    -- player is the string that the player is from, text is the text to filter
end

###From the client:

wait()
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local text = script.Parent

local ChannelBox = PlayerGui.IntroP2.intop2fr.ChannelBox
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FilterText = ReplicatedStorage:WaitForChild("FilterText")

-- listen for the text to change 
ChannelBox:GetPropertyChangedSignal("Text"):Connect(function()
    text.Text = FilterText:InvokeServer(ChannelBox.Text) -- the text returned by the server
    -- sets text to what the server filtered 
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.