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

how do I make a script affect every part in a group?

Asked by 2 years ago

im trying to change the color of every part in a group and I dont know how to do it, ive tryed to do an in pairs thing and it only changed one parts color in the group

this is what my script looks like

while true do 
    for i, v in pairs(game.Workspace:WaitForChild('stage1').stagetest:GetChildren()) do

        if v:IsA('Part') then 

            wait(math.random(1,5))

            v.BrickColor = BrickColor.new("Lime green")


            wait(math.random(1,5))
            v.BrickColor = BrickColor.new("Really red")


        end
    end
end

im trying to affect items in a group that is inside of another group so thats why its stage1.stagetest

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

You're super close , all you need to do is change where your wait is. Right now you're changing every individual part and waiting 1 to 5 seconds. If you put the wait right before you end the while loop and add one more for loop to change the color you will change every part at what looks like the same time. Your new script would look like this:

while true do 
    for i, v in pairs(game.Workspace:WaitForChild('stage1').stagetest:GetChildren()) do

        if v:IsA('Part') then 

            v.BrickColor = BrickColor.new("Lime green")

        end
    wait(math.random(1,5))
    for i, v in pairs(game.Workspace:WaitForChild('stage1').stagetest:GetChildren()) do
        if v:IsA("Part") then
            v.BrickColor = BrickColor.new("Really red")
        end
    end

    wait(math.random(1,5))
end
Ad

Answer this question