I'm working on a lego mini figure to make some fun animations, but rigging the hand of the lego man isn't going too well, at first the hand looks good and nothing sticks out of the arm. When i start to rotate the hand, the back of the hand sticks out the side of the arm, is there a way to make a simple rig to fix that? the hand is parented by a bone relative, I've tried using envelope weights and automatic weights
First I would make sure your hand bone is aligned with the hand mesh's axis of rotation. It's a little hard to tell from the screenshots.
It is likely that bone envelope weights/automatic weights will parent the hand to more than just the hand bone, as they are designed for smooth deformations of non-rigid characters.
Painting this minifig's weights is actually much easier! You can do it in edit mode. If you go into the Object Data tab of the Properties window, there should be a section that lists vertex groups. These correspond to the bones of your armature, if you've created automatic bone weights. When in edit mode, you can assign the bone weight values here directly.
I would start by using automatic weights, then going through each item in the vertex weights list, removing all vertices from that bone group (to remove the unwanted bone influence you're getting), and then assigning only the vertices you want.
This is a much faster way for rigid parts that are 100% influenced by only one bone. For smoothly deformed things like skin, weight painting is better.
You can also separate the parts and parent them as objects to the bones of your skeleton.