When used for either sports or sleeping, the efficacy of over-the-counter mouthguards depends on a few things, such as these:
Protecting your teeth from grinding with an over-the-counter mouthguard is absolutely better than not protecting them at all. However, if your jaw moves enough to move or dislodge the mouthguard during sleep the mouthguard will no longer protect your teeth.
If you clench your teeth extremely hard, you may end up biting through the plastic or breaking the mouthguard which, again, would leave your teeth unprotected. If this sounds like your teeth grinding habits, a custom-fit mouthguard is going to be better suited to your needs.