My animated sprite wont play when action just pressed

so ive been working on an attack but when the action is pressed it plays one frame and stops heres the code if it helps
func attack():
var overlaping_object = $attack_area.get_overlapping_areas()

for area in overlaping_object:
	var parent  = area.get_parent()
	print(parent.name)
	
attacking = true
if attacking == true:
	sprite_2d.animation = "attack"
else:
	sprite_2d.animation = "idle"

Do you play other animations like running/walking/idle every frame in a _physics_process or _process function?

OHHHHHHHHHHH my bad i put the animation in the wrong place sorry about that