Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

3 comments

0

Thanks but it's giving me an error message. Workspace.Model.Script:11: '}' expected (to close '{' at line 5) near 'Color3'

0

There was a missing comma in the list of colors. Edited the answer. Enjoy!

0

Oh! Thank you so much I really appreciate the help!

This discussion is preserved as it was. New answers, comments, and votes are closed.