It's because the player not overlapping ground overrides everything, it'll never check if the player is overlapping ground. You need to separate them out.
If player is not overlapping ground > do this.
If player is overlapping ground
ground is not on layer 3 > do this.