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

How do you get all children of all children?

Asked by
Scaii_0 145
6 years ago

So I have a model with a load of scripts. The script (when enabled) enables the particle emitter in each part. So, how would I enable the scripts in each part in the model?

Thanks in advance.

2 answers

Log in to vote
0
Answered by 6 years ago

You should not be using a script for each particle emmiter so you should change your code to handle all particle emmiters in one script.

Roblox now includes a function to do this for us and it is far faster than using Recursion. The function is GetDescendants which will return an array of instances belonging to that instance.

Though it is a bad idea to enable and disable scripts you can use the code to do this task.

for _, itm in  pairs(ins:GetDescendants()) do
    if itm:IsA('Script') then
        itm.Enabled = true
    end
end

I hope this helps.

Ad
Log in to vote
0
Answered by 6 years ago
for i,a in pairs(thing1:GetChildren()) do
    -- a is the nearest children to the root parent
    if a:IsA("BasePart") then
        for i,b in paris(thing2:GetChildren()) do
            -- b is the children of thing1
            if b:IsA("Script") then
                b.Disabled = false
            end
        end
    end
end

Dunno is that what you're asking for :thonk:

0
Model>Part>Script + Part>Script + Part>Script Scaii_0 145 — 6y
0
A model has a bunch of parts in it. Each part has a script in it, I want to enable those. Scaii_0 145 — 6y
0
“in paris” ??? LeadRDRK 437 — 6y

Answer this question