# How would I check if this puzzle is completed?

Hello. I am currently making a puzzle where you can click on one of the fields and then it rotates clockwise. This is not UI but models. Currently I’m trying to figure out how I would check to see if there is a connection in the lines from point a to point b. Does anybody know a way of checking?

Any help appreciated!

Is the puzzle different every time someone plays? If not then maybe you could check the rotation of the models?

You could find the position of the moving white square and check to see if it reaches the CFrame of the end arrow

It wouldn’t be different but I think there would be multiple ways to get the line connected.

In that case @Dfn150 's idea might work

There isn’t any white moving square that’s just the TeamCreate. All the squares except the red ones are moveable.

Each tile needs to be represented programmatically in a 2D table. You can get a tile by doing `gridTable[x][y]`
Each tile in the table needs to specify type and rotation. If it’s a T for example, you need to check both paths from the T, one at a time, and follow them until the end. It should be recursive.

``````local getNextTile
function getNextTile(x, y)
if isEndPoint then return true end -- replace isEndPoint with a condition to check if this is the end
if isOffTheGrid then return nil end -- replace isOffTheGrid with a condition to check if this tile is even valid
nextX, nextY = -- calculate next position based on rotation
otherX, otherY = -- other next position if this is a T
if thisTileIsT then
return getNextTile(nextX, nextY) or getNextTile(otherX, otherY)
else
return getNextTile(nextX, nextY)
end
end
``````

Call this function with the start position, and it will return true if the connection is complete.
Also you’ll need to check if the next tile is oriented correctly to receive the incoming line, I forgot to add that in.

Sorry I am not the best at this type of scripting. You say “you need to check both paths from the T” but there is three possible connections to check? And would `x` be “T” for example? And `y` the tiles rotation? How would I get the rotation? I also don’t know how I would check if the next one is oriented correctly.

Both paths from T because the current will be coming from one current already. x and y is the position.

1 Like

Oh, I see now. I was a little confused there