What you want to do here is change the priority of the animation. You can change this in the animation editor. There are 4 different priorities:
Core - Lowest Priority, all animations in this will not be played over the others. Roblox animations are this priority
Action - Second Lowest. Will play over Core, but not anything else
Movement - Second Highest, plays over Action and Core, but not Idle.
Idle - Highest Priority. Will play over any other animation.
To change these, go to your animation editor. Load in your animations with the import tool, and go to settings > priority > movement. You don’t want this to be Idle as that would cause it to play over your idle animation.
Actions are named respectfully, so the attack animation should be an ACTION, and your walk animation should be MOVEMENT. Other than that, your script looks fine to me.