Check Color of all Parts in a Model

I’ve created a model, and inside of it are 32 parts. I want to be able to check each part in it to see if they are all the same color, but I am unaware as to how I would do that.

Each part has a ClickDetector, as well as a script inside of it to change the color of the surrounding parts.
Ex:

It is a Lights Out puzzle if you are familiar with it. The goal of it is to get the entire board black, so I want to check if every part is black, and then print out that they are all black if so.

I apologize to anyone who finds this simple, but I do not have much experience with scripting.

local isAllBlack = true
for _, part in ipairs(model:GetChildren()) do
    if not part:IsA("BasePart") then continue end
    if part.Color3 ~= whateverColorHere then
        isAllBlack = false
    end
end
1 Like
function isAllBlack()
	for i, v in pairs(workspace.Model:GetChildren()) do
		if v.Color ~= Color3.new(0, 0, 0) then
			return false
		end
	end
	return true
end

local isAllBlack = isAllBlack()

Here’s a function which can be called whenever required and will check if all parts of the model are black.

1 Like