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

How to make all parts within a model change color in sync?

Asked by
snarns 25
7 years ago

I'd like for all of the parts within a single model to change color at the same time. I currently have this script inside every single part that needs to change color but it just gets messy and they don't always change in sync.

while true do 
script.Parent.Color = Color3.new(0,204,255)
wait(1.1) 
script.Parent.Color = Color3.new(0,255,0)
wait(1.1)
script.Parent.Color = Color3.new(255,255,0)
wait(1.1)
script.Parent.Color = Color3.new(255,0,0)
wait(1.1)
script.Parent.Color = Color3.new(153,0,153)
wait(1.1)
script.Parent.Color = Color3.new(0,0,255)
wait(1.1)
end 

If I could get help calling all of the children within a model and changing them together that would help me so much.

1 answer

Log in to vote
0
Answered by
duckwit 1404 Moderation Voter
7 years ago
Edited 7 years ago

Here you go, with some extra indirection and parametrisation thrown in:

local model = script.Parent
local delta = 1.1 -- time between colour changes

--list of colors to cycle through
local colors = {
            Color3.new(0,204,255), 
            Color3.new(0,255,0),
            Color3.new(255,255,0),
            Color3.new(255,0,0),
            Color3.new(153,0,153), --EDIT: missing comma
            Color3.new(0,0,255)
              }

-- infinite loop
while true do
    --loop through each of the colors
    for _, c in pairs(colors) do
        --for each color, set all of the parts in the model to that color
        for _,p in pairs(model:GetChildren()) do
            --make sure this child is a part
            if p:IsA("BasePart") then
                p.BrickColor = BrickColor.new(c)
            end
        end
        wait(delta) --wait 'delta' seconds before next color
    end
end 

Insert into the model whose parts you want to change color. Edit the list of colors or the time delta to tweak the animation and cycling through the colors.

0
Thanks but it's giving me an error message. Workspace.Model.Script:11: '}' expected (to close '{' at line 5) near 'Color3' snarns 25 — 7y
0
There was a missing comma in the list of colors. Edited the answer. Enjoy! duckwit 1404 — 7y
0
Oh! Thank you so much I really appreciate the help! snarns 25 — 7y
Ad

Answer this question