Help with pattern mini-game

So I am trying to make this mini game from a lot of games.

This is what that is:
Pattern minigame

What you have to do is copy a pattern and if you get the correct one you will win.

This is what I have so far:
For context there is a boolvalue and clickdetector in each part.

local PatternModel = script.Parent


local Pattern = {--I also don't know if this is the right way to set the pattern
	P1 = true,
	P2 = false,
	P3 = true,
	P4 = false,
	P5 = true,
	P6 = false,
	P7 = true,
	P8 = false,
	P9 = true
}

function check()
	-- I don't know how to check if the pattern matches
end

for i, v in pairs(PatternModel:GetChildren()) do
	if v:IsA("Part") then
		v.ClickDetector.MouseClick:Connect(function()
			if v.Status.Value == false then
				v.Status.Value = true
				v.BrickColor = BrickColor.new("Really black")
				check()
			else
				v.Status.Value = false
				v.BrickColor = BrickColor.new("Institutional white")
				check()
			end
		end)
	end
end

1 Like

I have come up with this:

local PatternModel = script.Parent


local Pattern = {
	true,
	false,
	true,
	false,
	true,
	false,
	true,
	false,
	true
}

function check()
	for i, v in pairs(PatternModel:GetChildren()) do
		if v:IsA("Part") then
			if v.Status.Value == Pattern[i] then
				print("Correct")
			end
		end
	end
end

for i, v in pairs(PatternModel:GetChildren()) do
	if v:IsA("Part") then
		v.ClickDetector.MouseClick:Connect(function()
			if v.Status.Value == false then
				v.Status.Value = true
				v.BrickColor = BrickColor.new("Really black")
				check()
			else
				v.Status.Value = false
				v.BrickColor = BrickColor.new("Institutional white")
				check()
			end
		end)
	end
end

But it prints correct all the time.

Edit:
I found something that works, but it probably isn’t the best way to do this:

local PatternModel = script.Parent

local P1 = PatternModel.P1
local P2 = PatternModel.P2
local P3 = PatternModel.P3
local P4 = PatternModel.P4
local P5 = PatternModel.P5
local P6 = PatternModel.P6
local P7 = PatternModel.P7
local P8 = PatternModel.P8
local P9 = PatternModel.P9

local Pattern = {
	P1 = true,
	P2 = true,
	P3 = true,
	P4 = true,
	P5 = true,
	P6 = true,
	P7 = true,
	P8 = true,
	P9 = true
}


function check()
	if P1.Status.Value == Pattern.P1 and
		P2.Status.Value == Pattern.P2 and
		P3.Status.Value == Pattern.P3 and
		P4.Status.Value == Pattern.P4 and
		P5.Status.Value == Pattern.P5 and
		P6.Status.Value == Pattern.P6 and
		P7.Status.Value == Pattern.P7 and
		P8.Status.Value == Pattern.P8 and
		P9.Status.Value == Pattern.P9 then
		print("Correct")
	else
		print("Wrong")
	end
end

for i, v in pairs(PatternModel:GetChildren()) do
	if v:IsA("Part") then
		v.ClickDetector.MouseClick:Connect(function()
			if v.Status.Value == false then
				v.Status.Value = true
				v.BrickColor = BrickColor.new("Really black")
				check()
			else
				v.Status.Value = false
				v.BrickColor = BrickColor.new("Institutional white")
				check()
			end
		end)
	end
end

How about something like this?

local patternModel = workspace
local black = BrickColor.new("Really black")
local white = BrickColor.new("Institutional white")

local pattern = {
	black,
	white,
	black,
	white,
	black,
	white,
	black,
	white,
	black
}

function CheckPattern()
	for i = 1, #pattern do
		if patternModel["P" .. i].BrickColor ~= pattern[i] then
			return false -- at least one of the parts of the pattern is wrong
		end
	end
	return true -- for loop completed, all parts of the pattern are correct
end

EDIT: Fixed something.