Lights Out Puzzle

It’s pretty simple, I’m just attempting to make a 3x3 lights out puzzle like this:


This is what my model looks like:
Screenshot (198)

I want all the bricks to be a certain color for the puzzle to be complete.

How could I use one script in the model to detect which brick is clicked, and then change the surrounding bricks’ colors according to what color they are?

1 Like

I would do something like this:

local bricks = --table of bricks (use getchildren or sm)

for i,v in pairs(bricks) do
    local cd = --clickdetector
        local num = tonumber(v.Name)
        if (num+1)/3 == math.floor((num+1)/3) then
            for i,b in pairs(bricks) do
                if tonumber(b.Name) == tostring(num-1) or tonumber(b.Name == tostring(num+1)) then
                    b.BrickColor = b.BrickColor =="Black") and"Light Yellow") or"Black")

This is a partly finished script, you will need to finish the rest yourself, but it should give enough of an example of how to do it. Also, make sure to name all of the bricks in order like this:
1 2 3
4 5 6
7 8 9

1 Like