Your character only moves when move_and_slide is being called and you set the velocity before move_and_slide to a new value, which ignores your other velocity value.
Basically your “velocity = Vector2.ZERO” call gets overwritten. It would have also failed because you set the velocity again if you are attacking or not. The new code checks if you are attacking and only if not it sets the velocity.
In general: Look up state machines on youtube, you already had 2 problems which can be easily fixed by using state-machines. They are a fundamental building block in gamedev