It's because when you press space to set an animation, one of your speed checks is always true and overrides the one time setting of that animation. You'll need to set some kind of character state by way of global variable when the character goes to punch, and under the speed checks say when character is not set to punch, so the punch animation can play. You then have punch on a timer so say after 1 second you set him back to not punching, the other idle animations would then take effect.