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

Need help with GetChildren?

Asked by
Seraine 103
10 years ago

At the moment the bricks named Part1 change colour one by one. What do I have to add so that the bricks with the same name change colour at the same time?

local parts = Workspace:GetChildren()

for _, child in ipairs (parts) do -- Generic for loop
    if child.Name == 'Part1' then 
while true do
        child.BrickColor = BrickColor.new("Hot pink")
        wait(0.5)
        child.BrickColor = BrickColor.new("Bright red")
    wait(0.5)
    end
end

1 answer

Log in to vote
0
Answered by 10 years ago

Ah, I ran into pretty much the same problem a few weeks ago. Simply switch the for loop and the while loop around. like this:

while true do
    for _, child in pairs(parts) do
        if child.Name == 'Part1' then
            child.BrickColor = BrickColor.new("Hot pink")
        end
    end
    wait(0.5) -- You also have to have 2 for loops, one to color bricks red, one to color them pink
    for _, child in pairs(parts) do
        if child.Name == 'Part1' then
            child.BrickColor = BrickColor.new("Bright red")
        end
    end
    wait(0.5)
end

Your code will go down the list of bricks and make each one flash while true. My code, while true, goes down the list and instantly does half of the flash, then goes down again and completes the flash. It all depends on what you want it to do. Hope this helps! :)

Ad

Answer this question