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

FindFirstChild through every descendant?

Asked by 8 years ago

What I am trying to do, since I accidentally installed an infected plugin, remove all the scripts it added.

As it was put into every model in the place, duplicated infinitely, I was wondering how I would make this search through every descendant of every descendant.

A = game.Workspace:GetChildren()

for i,v in pairs(A) do
    if v.ClassName == "Script" then
        if v:FindFirstChild("4D Being") then
            v:remove()
        end
    end
end

1 answer

Log in to vote
1
Answered by
rexbit 707 Moderation Voter
8 years ago

Easy, use a Changed event, it will clean, but not any new elements.

A = game.Workspace:GetChildren()


game.Workspace.Changed:connect(function()
    for i,v in pairs(A) do
        if v.ClassName == "Script" then
            if v:FindFirstChild("4D Being") then
                v:remove()
           end
        end
    end
end)

Ad

Answer this question