Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you get all children of all children?

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

✓ Accepted answer

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.

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:

3 comments

0

Model>Part>Script + Part>Script + Part>Script

0

A model has a bunch of parts in it. Each part has a script in it, I want to enable those.

0

“in paris” ???

This discussion is preserved as it was. New answers, comments, and votes are closed.