hey guys I've been trying to train my dog for about a month now and he seems to only listen to me when he wants to

sometimes he does what i say and sometimes he doesnt, when we are indoors he listens to me more but when I take him out he does anything he wants. Can someone give me pointers on how to train him more effectively ? thiss is my first dog btw