Color-changing script won't work

Hello. I was trying to script a color-changing brick from what I’ve learned from scripting.
When I tested it out, it doesn’t work.
Script:

local rgb = script.Parent
while true do
	for _, PartsInModel in ipairs(rgb:GetChildren()) do
	PartsInModel = Color3.new(1, 0, 0)
	wait(0.05)
	for _, PartsInModel in ipairs(rgb:GetChildren()) do
	PartsInModel = Color3.new(1, 0.25098, 0)
	wait(0.05)
	for _, PartsInModel in ipairs(rgb:GetChildren()) do
	PartsInModel = Color3.new(1, 0.317647, 0)
	wait(0.05)
	for _, PartsInModel in ipairs(rgb:GetChildren()) do
	PartsInModel = Color3.new(1, 0.45098, 0)
	wait(0.05)
end

Model in explorer:
image
Output:

1 Like

You have forgotten the .Color

New Script:

local rgb = script.Parent
while true do
wait()
	for _, PartsInModel in ipairs(rgb:GetChildren()) do
    if PartsInModel:IsA("Part") then
	      PartsInModel.Color = Color3.new(1, 0, 0)
	      wait(0.05)
       end
    end
end

Also, you forgot the end in for loops.

Oh, you also want to check if it’s a Part considering you have a Part and a Script in the Model.

You need to add an end on every for i,v in pairs.

1 Like

Got a new error.


EDIT: ok nevermind realized the solution was changed

for loops have to end with an end

for i = 1, 2 do
   --example
end

Your code should look something like this:

local rgb = script.Parent
while true do
	for _, PartsInModel in ipairs(rgb:GetChildren()) do
	PartsInModel = Color3.new(1, 0, 0)
	wait(0.05)
    end
	for _, PartsInModel in ipairs(rgb:GetChildren()) do
	PartsInModel = Color3.new(1, 0.25098, 0)
	wait(0.05)
    end
	for _, PartsInModel in ipairs(rgb:GetChildren()) do
	PartsInModel = Color3.new(1, 0.317647, 0)
	wait(0.05)
    end
	for _, PartsInModel in ipairs(rgb:GetChildren()) do
	PartsInModel = Color3.new(1, 0.45098, 0)
	wait(0.05)
    end
end