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

Why Isn't FilterStringAsync Working with My Custom Chat GUI?

Asked by
8391ice 91
7 years ago

So I'm in the process of making a custom chat GUI for my game. Of course, in order to prevent my game from being shut down, it must be done with ROBLOX's filters, so I have to use FilterStringAsync. The way I chose to accomplish this was by having a folder named "ChatStorage" being placed in the Workspace and a script where whenever a player chats, it creats a StringValue with the name of it as the player who chatted and the value as what the player said that is parented to the ChatStorage.

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message)
        local stringVal = Instance.new("StringValue", game.Workspace.ChatStorage)
        stringVal.Name = player.Name
        stringVal.Value = message
    end)
end)

A LocalScript is in the PlayerGui and it fires whenever a child is added to the ChatStorage. This is the main script; it's where the FilterStringAsync function takes place and where the player's message is scripted to appear from. However, when all of this is ran, I get absolutely no output whatsoever. Nothing is added to the ChatBox, where the messages are supposed to appear, and when I check inside of the Developer Console in the actual game, I still see nothing outputting.

local ChatService = game:GetService("Chat")

cb1 = script.Parent.cb1 --These are the names of the 8 chatboxes in the Chat GUI.
cb2 = script.Parent.cb2
cb3 = script.Parent.cb3
cb4 = script.Parent.cb4
cb5 = script.Parent.cb5
cb6 = script.Parent.cb6
cb7 = script.Parent.cb7
cb8 = script.Parent.cb8

game.Workspace.ChatStorage.ChildAdded:connect(function(child) --When a new child is added to the aforementioned ChatStorage, this fires.
    if (child:IsA("StringValue")) == true then --Checking to see if it's an actual message.
        local message = child.Value --Setting the message.
        local sender = child.Name --Setting the sender.
        local player = game.Players.LocalPlayer --Setting the receiver.
        local filteredMessage = ChatService:FilterStringAsync(message, sender, player.Name) --Setting the FilterStringAsync function.
        print(filteredMessage) --I tried printing it and I got no output.
        cb1.Text = cb2.Text --This is just for moving the messages up after every entered message.
        cb1.TextColor3 = cb2.TextColor3
        cb2.Text = cb3.Text
        cb2.TextColor3 = cb3.TextColor3
        cb3.Text = cb4.Text
        cb3.TextColor3 = cb4.TextColor3
        cb4.Text = cb5.Text
        cb4.TextColor3 = cb5.TextColor3
        cb5.Text = cb6.Text
        cb5.TextColor3 = cb6.TextColor3
        cb6.Text = cb7.Text
        cb6.TextColor3 = cb7.TextColor3
        cb7.Text = cb8.Text
        cb7.TextColor3 = cb8.TextColor3
        if sender.Name == "8391ice" then --If it's my name, I get a cool Owner tag and a red-colored message :P
            cb8.Text = "[Owner] 8391ice: " ..filteredMessage
            cb8.TextColor3 = Color3.new(1, 0, 0)
        elseif sender.Name == "Server" then --If it's a message like a player leaving or entering, the Server says it and it gets a tan-colored message.
            cb8.Text = "[Server:] " ..filteredMessage
            cb8.TextColor3 = Color3.new(1, 1, 127/255)
        else --Anything else is just assumed to be a player, and he or she is given white text.
            cb8.Text = sender.. ": " ..filteredMessage --Message is set to the filtered message.
            cb8.TextColor3 = Color3.new(1, 1, 1)
        end
    end
    wait(.1)
end)

Do any of you think you might be able to spot what's wrong with this script? I'm just completely stuck right now and I have nowhere else to turn but ScriptingHelpers. Thanks!

0
According to the wiki, you need to use the actual player object instead of their name for both the sender and the receiver. Spongocardo 1991 — 7y

2 answers

Log in to vote
1
Answered by
Valatos 166
7 years ago

You need to have the player object instead of the player name in the filter part.

0
Thank you so much! I had no idea that I had to use objects instead of the names! 8391ice 91 — 7y
0
I didn't either, I had the same problem. It worked when i tried to use the object instead Valatos 166 — 7y
Ad
Log in to vote
-1
Answered by 7 years ago

You can't filter with local script

0
o thats cool csgoislove 0 — 7y
0
i guess i should be more active :P csgoislove 0 — 7y

Answer this question