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

Change color of all bricks called "Lamp2"?

Asked by
Flax42 10
7 years ago
Edited 7 years ago

So I've got many bricks in different models called "Lamp2". How do i change color of all of them to another color?

Model1 { Lamp2 Brick Brick } Model2 { Lamp2 Brick Brick }

Would there be a way to change all of the colors of them?

EDIT: A bit of an explanation I have a button in workspace and i have several other models in workspace. When I press the button I'd like to make all bricks called "Lamp2" to change color to say "Bright red". So when the player pushes the button I want to change the brick called "Lamp2" inside of different models.

2 answers

Log in to vote
0
Answered by
jakedies 315 Trusted Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

If all of these lamps are in a model, you can iterate over all children of workspace and if Lamp2 exist as a child, change the color.

local children = workspace:GetChildren()
for idx = 1, #children do 
    local child = children[idx]
    if child:IsA("Model") then  -- child is a model
        local lamp = child:FindFirstChild("Lamp2")
        if lamp then -- lamp exists
            lamp.Color = blah -- new color here
        end
    end
end

In short, for every child of workspace: if it's a Model and a child named Lamp2 exists: Change the color of Lamp2

Ad
Log in to vote
0
Answered by 7 years ago

An easier way is just looking up Lamp2 in workspace and selecting them all and choosing the brick color :)

Answer this question