Unfortunately, by the time the mouthing turns into painful nips, you’ve already taught your puppy that he gets lots of attention and playtime by “biting” your hands.
From his perspective, if you start suddenly scolding him for it, you’re changing the rules in the middle of the game. You’ll confuse him and undermine his trust in you.
Ideally, you should never allow your dog to think it’s okay for his teeth to come into contact with human skin. Not only does that mean not allowing your puppy to mouth your hands, it also means not playing with your older dog by trying to wrestle a toy out of his mouth. But that’s not much help if you’ve already done your part to create a bad habit.
In that case, you need to teach your dog that letting his teeth come in contact with your skin means an end to the fun. If your dog nips at you, stop everything. If he’s in your lap, put him on the floor. If you’re playing with a toy, set it out of reach.
Don’t touch him, don’t talk to him, and don’t look at him. As soon as he sits calmly, praise him and play until the next time you feel his teeth. Then stop and do the routine again. It may take a few times, especially if he’s an older dog, but he’ll figure it out.