How can I get all the children in one variable?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Being able to change all of the children in a model.

  2. What is the issue? Here, the image shows the error in console. I tried to change the transparency of the ambience lighting, however it does not allow me to cast the value to the object.

Here is line 55.

  1. What solutions have you tried so far? I can’t really phrase it properly for searches. I have tried GetChildren and GetDescendants.

If you would like me to send you the model to test it, you can reply for a download.
Please tell me if I made a dumb mistake again. I really want this fixed ASAP. Help is much appreciated.

I think you want to use this,

for i, v in pairs(yourmodel:GetDescendants()) do
edit v
end

1 Like

What if I have multiple models? I need to do this 18 times: 8 times for the lasers, 8 more times for the startup lasers, 1 time for the startup ambient lighting, and 1 last time for the normal ambient lighting.

You can use this

for i, v in pairs(model:GetDescendants()) do
if v:IsA("InstanceNamesUsedInModel") then
--change properties
end
end

Here’s an example

for i, v in pairs(model:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("MeshPart") then
    v.CanCollide = false
end
end
1 Like

Are those, (lasers, ambient etc) all in a folder/model? Or just in the workspace, if their in a folder/model you could just use 2 loops

This is what the directory looks like.


for i, v in pairs(script.Parent:GetDescendants()) do
if v.Name == “Laser” or v.Name == “StartupLaser” then
do stuff with v
end
end

I think you will have to do this twice tho

1 Like

I’d suggest using if V:IsA(“InstanceName”) instead since that’s more practical and efficient than using if v.Name you’ll have to change the name of each child if you were to use if v.Name, However if you only want to edit specific parts then you can use the GetChildren() function for the specific models or if v.Name as @Mishaho mentioned!

3 Likes

Ayy! I got the Ambience lighting to work. Now for the lasers…

Problem: lasers don’t work anymore. I’m going to try to move all the lasers into one model/folder.

Make sure to mark the problem as resolved for other people to find useful

1 Like

Thank you! It worked! Now I will need to find out how to make a good camera shake, but i’ll do that in another post.

1 Like

I’m glad it worked, and good luck with the camera shake.

1 Like