It’s pretty simple, I’m just attempting to make a 3x3 lights out puzzle like this:
This is what my model looks like:
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?
local bricks = --table of bricks (use getchildren or sm)
for i,v in pairs(bricks) do
local cd = --clickdetector
cd.MouseClick:Connect(function()
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 == BrickColor.new("Black") and BrickColor.new("Light Yellow") or BrickColor.new("Black")
end
end
end
end)
end
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