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

How to change one or more properties of all a object's children at once?

I have a light system in my place and would like to change the colors etc of the lights and the brick they are in:

----Model (Lights)

--------Brick (Light)

------------Surface Light

--------Brick (Light)

------------Surface Light

--------Brick (Light)

------------Surface Light

--------Brick (Light)

------------Surface Light

--------Brick (Light)

------------Surface Light

How do you implement this so I could add:

game.Workspace.Lights.Light.SurfaceLight.Color = Color3.new("0, 0, 0")

for example (Maybe not a correct example, just off the top of my head).

Thanks!

2 comments

0

In the future, I suggest using puush or some other screenshotting tool to show us an Explorer hierarchy. It's a little easier to comprehend that way.

0

Noted.

1 answer

✓ Accepted answer

There isn't one property that is shared by all of the objects, so you can't do this quite 'all at once' -- you can't set properties of all children, but you can set properties of each child.

To do this, we need a for loop (which does something for each thing) and a list of children:

local children = model:GetChildren()

for _, child in pairs(children) do
	-- do the following for each `child` of `model`:
	child.SurfaceLight.Color = Color3.new(0, 0, 0)
end

Note that Color3.new takes three numbers, not one string.

6 comments

0

Thanks, BlueTaslem, oh and by the way, I know that Color3.new thing, just rushing, thanks though, oh and your portal games are great. I'm assuming for model:GetChildren() I specify the location, e.g. game.Workspace.Lights:GetChildren()?

0

You should demonstrate for him that Color3 values need to be out of 255.

1

Sharpthy: That's right

0

Well, that's a suprise.#

0

How can I change a property of the children of the children?

0

Nevermind, stupid question!

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