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

Chat filter resulting in a nil value? *follow up on previous question*

Asked by
Donut792 216 Moderation Voter
5 years ago
Edited 5 years ago

alright so on my previous question i got a answer from incap to use :FilterStringForBroadcastAsync() which i did but im not entirely sure how to use it in the chat system i have set up. This chat system is a series of GUI elements and once a player chats it creates a textlabel and sets it in the appropriate place which did work before adding filter which now results in "a nil value" the script will say when a player joins and leaves but now it wont show their chat and instead give an immediate nil value error.

lines 93 and 100 are the lines with :FilterStringForBroadcastAsync() on them everything else works fine

script:

local chats = script.Parent.Chats
local last

function newChat(msg,plr)
    local plrid = plr.UserId
    if #msg > 0 then
        for i, c in pairs(chats:GetChildren()) do
            c.Position = c.Position - UDim2.new(0, 0, 0.1, 0)
        end
        local newMessage = script.Message:clone()
        if #chats:GetChildren() == 10 then
            chats:GetChildren()[1]:Destroy()
        end

        if plrid == 38270341 then
        newMessage.TextColor3 = script.Owner.Value
        newMessage.Text = "[OWNER] " .. plr.Name ..": ".. msg

        elseif plrid == 291995028 or plrid == 131541716 or plrid == 41163273 or plrid == 291995028 then
        newMessage.TextColor3 = script.Admin.Value
        newMessage.Text = "[ADMIN] " .. plr.Name ..": ".. msg

        elseif game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plrid,5286942) then
        newMessage.TextColor3 = script.VIP.Value
        newMessage.Text = "[VIP]" .. plr.Name ..": ".. msg

        else 
        newMessage.Text = plr.Name ..": ".. msg
        end

        newMessage.Position = UDim2.new(0, 0, 0.9, 0)
        newMessage.Parent = chats
        last = newMessage
    end
end

function join(plr)
    for i, c in pairs(chats:GetChildren()) do
            c.Position = c.Position - UDim2.new(0, 0, 0.1, 0)
        end
        local newMessage = script.Message:clone()
        if #chats:GetChildren() == 10 then
            chats:GetChildren()[1]:Destroy()
        end
        if plr.UserId == 38270341 then
        newMessage.Text = "[CONSOLE] " .. plr.Name .. " joined the server!"
        newMessage.TextColor3 = script.OwnerJoin.Value
        newMessage.Position = UDim2.new(0, 0, 0.9, 0)
        newMessage.Parent = chats
        last = newMessage
        else
        newMessage.Text = "[CONSOLE] " .. plr.Name .. " joined the server!"
        newMessage.TextColor3 = script.CONSOLE.Value
        newMessage.Position = UDim2.new(0, 0, 0.9, 0)
        newMessage.Parent = chats
        last = newMessage
    end
end

function left(plr)
    for i, c in pairs(chats:GetChildren()) do
            c.Position = c.Position - UDim2.new(0, 0, 0.1, 0)
        end
        local newMessage = script.Message:clone()
        if #chats:GetChildren() == 10 then
            chats:GetChildren()[1]:Destroy()
        end
        if plr.UserId == 38270341 then
        newMessage.Text = "[CONSOLE] " .. plr.Name .. " left the server!"
        newMessage.TextColor3 = script.OwnerJoin.Value
        newMessage.Position = UDim2.new(0, 0, 0.9, 0)
        newMessage.Parent = chats
        last = newMessage
        else
        newMessage.Text = "[CONSOLE] " .. plr.Name .. " left the server."
        newMessage.TextColor3 = script.CONSOLE.Value
        newMessage.Position = UDim2.new(0, 0, 0.9, 0)
        newMessage.Parent = chats
        last = newMessage
    end
end

game.Players.PlayerAdded:Connect(function(plr)
    join(plr)
end)

game.Players.PlayerRemoving:Connect(function(plr)
    left(plr)
end)

game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        msg:FilterStringForBroadcastAsync(msg)
        newChat(msg, plr)
    end)
end)

for i, player in pairs(game.Players:GetPlayers()) do
    player.Chatted:Connect(function(msg)
        msg:FilterStringForBroadcastAsync(msg)
        newChat(msg,player)
    end)
end
0
I don’t think you’re using :FilterStringForBroadcastAsync() correctly. Those are chat service functions, but you’re trying to use it on a string? Also the function doesn’t even exist! Remove the “Async” part. User#20279 0 — 5y
0
your last two events (line 91 and 98) are firing the newChat function at the same time (after someone chats) and i really dont think thats what you want Gey4Jesus69 2705 — 5y
0
yes what im trying to get is the game grabs what they say and filters out that string then sends it to newChat Donut792 216 — 5y
0
and yes with the Async part it still results in nil Donut792 216 — 5y

Answer this question