Create a hitbox part in the size of the piece, just like you already do in the script, which is cancollide = true, after checking if it collides with something, changes it to cancollide = false, if it is colliding, recalculates the path, or simply closes with a wall and continues elsewhere, if the collide_table = nil then proceed to the next piece.
all these steps you have already programmed, just check if there is something colliding and redirect to the function that will solve Voilà