If you want the player to only attack when not moving, simply add an event similar to the one below.
Keyboard > on [attack key] pressed >>> Player > set animation to [attack animation]
then, add a condition (right click on event and select add... and click condition).
Player > compare speed > equal to 0
and then add another event so you can get out of the attack animation.
I'm not positive if this part works unless you replace: on [attack key] pressed with [attack key] is down. try that.
Keyboard > on [attack key] released >>> Player > set animation to [default animation]
I hope this helps!
What if I want the attack animation to cause the player to stop moving? Example: you press Z and that causes the player to stop moving and start his attack animation.