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
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! :)