No idea on how to use Attacks of Opportunity

I am a new DM. My friends are new too to the game as well, so we are trying to get familiar with the rules.

One rule that we can’t get is the one on attacks of opportunity.

My friends say that you get one every single time a monster attacks because “If he attacks, then gets to lower his guard” but I find that unfair because they will get 2 attacks every single time.