Just hours ago I started trying to learn Godot and am following the my first 2d game tutorial, but I wanted to add one extra button that would make the player invincible just so I can understand actions other than moving. I've spent hours on this and figured out that the if statement used to start the "invincibility" animation just refreshes every frame but I still can't find a way to make that animation play and override the movement animations. Thank you in advance, it is appreciated.

For reference, the animation works when I replace my walking animation with it. Also, when I try using a While statement, it just crashes the second I press the space bar (invincibility button).

extends Area2D
@export var speed = 400 
var screen_size 
var is_invincible = false
func _ready():
	screen_size = get_viewport_rect().size

func _process(delta):
	var velocity = Vector2.ZERO 
	if Input.is_action_pressed("move_right"):
		velocity.x += 1
	if Input.is_action_pressed("move_left"):
		velocity.x -= 1
	if Input.is_action_pressed("move_down"):
		velocity.y += 1
	if Input.is_action_pressed("move_up"):
		velocity.y -= 1
	
	if velocity.length() > 0:
		velocity = velocity.normalized() * speed
		$AnimatedSprite2D.play()
	else:
		$AnimatedSprite2D.stop()
	
	position += velocity * delta
	position = position.clamp(Vector2.ZERO, screen_size)
	
	if velocity.x != 0:
		$AnimatedSprite2D.animation = "walk"
		$AnimatedSprite2D.flip_v = false
	# See the note below about boolean assignment.
		$AnimatedSprite2D.flip_h = velocity.x < 0
	elif velocity.y != 0:
		$AnimatedSprite2D.animation = "walk"
	
	if velocity.x < 0:
		$AnimatedSprite2D.flip_h = true
	else:
		$AnimatedSprite2D.flip_h = false
	
	if Input.is_action_pressed("invincible"):
		is_invincible = true
		$AnimatedSprite2D.animation = "invincible"
	if Input.is_action_just_released("invincible"):
		is_invincible = false
	
	if is_invincible != true:
		$AnimatedSprite2D.play("invincible")
		is_invincible = true

You can use another bool variable called "is_locked" (is_invincible?) and nest* with others if.
When false the player can move, when true cant' move.

var is_locked := false
if is_locked == false:
   if velocity.x != 0:
	$AnimatedSprite2D.animation = "walk"
        $AnimatedSprite2D.flip_v = false
        $AnimatedSprite2D.flip_h = velocity.x < 0
   elif velocity.y != 0:
        $AnimatedSprite2D.animation = "walk"
    if is_locked == false:
       move_and_slide()

*This can be considered a controversial method because of the complication it creates. In more complex uses it is advisable to rely on more complex processing systems.

    fatalox If I understand correctly, the animation would play because movement is locked and therefore the movement animations are as well. If that is the case, it won't solve my problem of wanting to understand how to override the movement animation with an action that can be done while moving. Like in Contra when you run and shoot at the same time, that'd override the normal movement. Or maybe it'd be more realistic to have different functions for movement animations but that sounds like it would get really convoluted if you have multiple animations for actions while moving. I'm not experienced at all with coding so thanks!

      Saber I see, you want to move but also be invincible. Sorry but what you mean by invincible? You take some kind of damage? Do you have an health value? Or is related to having no collision?
      If is related only on animations kinda make sense to me that two same animations override themself.
      Like you cant walk and running at same time without breaking the logic.
      But what is an invincible animation by the way?

        fatalox Invincible was just the easiest thing that I thought I could implement. Like the star power up in Mario. It's more about overriding animations than implementing something that makes sense. I figured out a solution after reading your suggestion though! I added a variable that would be needed to be true in order for the basic movement animations to play. I'd send a video of it but idk what kind of video type these forums support. Thank You!!

        extends Area2D
        @export var speed = 400 
        var screen_size 
        var walk_idle = true
        func _ready():
        	screen_size = get_viewport_rect().size
        
        func _process(delta):
        	var velocity = Vector2.ZERO 
        	if Input.is_action_pressed("move_right"):
        		velocity.x += 1
        	if Input.is_action_pressed("move_left"):
        		velocity.x -= 1
        	if Input.is_action_pressed("move_down"):
        		velocity.y += 1
        	if Input.is_action_pressed("move_up"):
        		velocity.y -= 1
        	
        	if velocity.length() > 0:
        		velocity = velocity.normalized() * speed
        		$AnimatedSprite2D.play()
        	else:
        		if walk_idle:
        			$AnimatedSprite2D.animation = "idle"
        	
        	position += velocity * delta
        	position = position.clamp(Vector2.ZERO, screen_size)
        	
        	if velocity.x != 0 and walk_idle:
        		$AnimatedSprite2D.animation = "walk"
        		$AnimatedSprite2D.flip_v = false
        	# See the note below about boolean assignment.
        		$AnimatedSprite2D.flip_h = velocity.x < 0
        	elif velocity.y != 0 and walk_idle:
        		$AnimatedSprite2D.animation = "walk"
        	
        	if velocity.x > 0:
        		$AnimatedSprite2D.flip_h = true
        	elif velocity.x < 0:
        		$AnimatedSprite2D.flip_h = false
        	
        	if Input.is_action_just_pressed("invincible"):
        		walk_idle = false
        		$AnimatedSprite2D.animation = "invincible"
        	elif Input.is_action_just_released("invincible"):
        		walk_idle = true
          Saber changed the title to [Solved] Newbie's sprite animation won't go past frame 0 .

          Saber Well done! Nesting looks an easy way to solving, but controversial as i say.
          I think the forum support any kind of img but limited to 2MB, so a very tiny one.

            fatalox I tried to upload an mp4 and under 1MB but it said it wasn't allowed. I can just do youtube videos though now that I figured that out. Thanks again