%brick.plant() returns an error.
Check that error.
If it is neither the error for floating (mid-air) or no error at all, it was being planted in something solid.
If you don't want it planting on players, vehicles, or items as well, then you need to learn about container searches, and that is too advanced to cover here.