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

How should I go about using FilterStringAsync?

Asked by
Xonois -3
5 years ago

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
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. Rare_tendo 3000 — 5y
0
Use it on the server, and it's game:GetService("Chat"):FilterStringForBroadcast(stringToFilter, playerFrom). User#23857 0 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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)
Ad

Answer this question