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!
EDIT: alternatively, if you want your player to stop when attacking and you're using plat former, use these commands:
Keyboard > [attack button] is down >>> Player > set Maximum speed to 0 > set acceleration to 0 > set deceleration to 0 > set animation to [attack animation]
Keyboard > [attack button] released >>> Player > set Maximum speed to [original max speed] > set acceleration to [original acceleration] > set deceleration to [original deceleration] > set animation to [default animation]
That might be more of what you're looking for.