Animation stuck when pressing attack too fast

Godot Version

4.2.1

Question

Hello! I’m working on a 2d platformer, and I’m looking for the solution for this issue: when player is spamming attack, sometimes animation stops on the last frame of the attack animation and other animation code stops working. Any help appreciated.
Here’s the code:
func update_animations(delta) → void:
if !is_attacking:
if velocity.x != 0 and velocity.y == 0 and !is_jumping:
anim_sprite.play(“run”)
elif velocity == Vector2(0, 0):
anim_sprite.play(“idle”)

	if velocity.y > 0:
		anim_sprite.play("fall")
		is_jumping = false
elif anim_sprite.animation != "attack_1" and anim_sprite.animation != "attack_2" and anim_sprite.animation != "attack_3":
	if attack_count == 1:
		anim_sprite.play("attack_1")
	elif attack_count == 2:
		anim_sprite.play("attack_2")
	elif attack_count == 3:
		anim_sprite.play("attack_3")
		attack_count = 1

func attack() → void:
#if attack_count == 1:
#anim_sprite.play(“attack_1”)
#attack_count += 1
#elif attack_count == 2:
#anim_sprite.play(“attack_2”)
#attack_count += 1
#elif attack_count == 3:
#anim_sprite.play(“attack_3”)
#attack_count = 1
is_attacking = true
can_attack = false
attack_count += 1

Full codes