Attack animation keeps repeating and doesn't go back to idle animation, I am desperate

The animation of the attack just repeat when i click J (attack input).
Here’s my code:

extends CharacterBody2D
const SPEED = 300.0
const JUMP_FORCE = -490.0

var gravity = 1700
var is_jumping := false
var isAttacking = false

@onready var animation := $anim as AnimatedSprite2D

func _physics_process(delta):
if not is_on_floor():
velocity.y += gravity * delta

if Input.is_action_just_pressed("up") and is_on_floor():
	velocity.y = JUMP_FORCE
	is_jumping = true
elif is_on_floor():
	is_jumping = false

var direction = Input.get_axis("left", "right") 
if direction:
	velocity.x = direction * SPEED
	animation.scale.x = direction 
	if !is_jumping:
		animation.play("run")
elif is_jumping:
	animation.play("jump")
else:
	velocity.x = move_toward(velocity.x, 0, SPEED)
	if !is_jumping and !isAttacking:
		animation.play("idle")
if Input.is_action_just_pressed("attack"):
	animation.play("attack")
	isAttacking = true
move_and_slide()

You set isAttacking to true but never reset it back to false so it won’t enter the block where you play the idle animation.

You’ll need to find a way to set isAttacking to false at some point.