On line 18, maybe try script:GetDescendants(), this also gets the children of the children. And if you want it to account for MeshParts and other types of part s, on line 20 you should use if brick:IsA("BasePart")
script:GetDescendants()
if brick:IsA("BasePart")