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

What is the correct usage of DescendantAdded?

Asked by 6 years ago

This is my code:

function FilterString(str)
    local filtered = game:GetService("Chat"):FilterStringForBroadcast(str,game.Players:GetPlayers()[1])
    if filtered ~= nil then
    return filtered
    end
    return "< Filter Failed >"
end
local sources = {
    "TextLabel",
    "Message",
    "Hint",
    "StringValue"
}
game.DescendantAdded:connect(function(desc)
    local long = desc:GetFullName()
    if long:find("Chat.Frame.ChatChannelParentFrame") ~= nil then
        return nil
    end
    print("got " .. desc.Name .. " from " .. long)
    if desc:IsA("TextLabel") then
        desc.Text = FilterString(desc.Text)
    elseif desc:IsA("TextButton") then
        desc.Text = FilterString(desc.Text)
    elseif desc:IsA("Message") then
        desc.Text = FilterString(desc.Text)
    elseif desc:IsA("Hint") then
        desc.Text = FilterString(desc.Text)
    elseif desc:FindFirstChild("Humanoid") then
        desc.Parent.Name = FilterString(desc.Parent.Name)
    else
        print(desc.Name .. " does not need to be filtered")
    end
end)

It should filter anything with text, but it doesn't work.

Answer this question