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

Children Of Children?

Asked by 10 years ago
for i,v in pairs (game.Workspace:GetChildren()) do
if v.Name == "Script" then
v.Script:Destroy()
end end

how would I get the children twice? Because I'm trying to remove all the scripts under the hats in the model hats.

0
Running in command bar btw. YellowoTide 1992 — 10y

1 answer

Log in to vote
1
Answered by
duckwit 1404 Moderation Voter
10 years ago

You really need to be using a recursive function here, because the Model that you describe may have more than just two levels of children, you should also check if an Instance is a Script by using the IsA() method, rather than seeing if it is called "Script".

This will work in the command bar too:

function DeleteScripts(instance)
    for _,v in pairs(instance:GetChildren()) do
        if v:IsA("Script") then 
            v:destroy()
        else 
            DeleteScripts(v) 
        end
    end
end

Then you can use it like this, by passing it the Model or Instance that you want the Scripts to be removed from:

DeleteScripts(workspace.Hats) --Insert your object path
0
Thank you sir! YellowoTide 1992 — 10y
0
It was my pleasure, YellowTide! :) duckwit 1404 — 10y
Ad

Answer this question