Slow down sprite frams

Godot Version

Godot 4.4.1

Question

Hey, never coded before, I don’t know code.
Wondering if theres a way slow down animation on AnimatedSprite2D for a specific action.

Game: Top down pixel RPG

I want my “crouch” animation to be slower to make it natural with the slower speed when crouching. I was trying to change the speed scale but my code never worked. It always shows an error and I have no idea what they mean.

Script is in the parent CharacterBody2D and AnimatedSprite2D child.

Here’s the code that works:

extends CharacterBody2D


@onready var anim: AnimatedSprite2D = $AnimatedSprite2D


var is_moving:bool = false
var dir:String = "none"
var speed:float = 80
var dash_spd:float = 140
var crouch_spd:float = 20


func _ready():
	pass

func _process(_delta):
	pass



	if Input.is_action_pressed("ui_left"):
		velocity = Vector2.LEFT * speed 
		is_moving = true
		dir = "left"

	elif Input.is_action_pressed("ui_right"):
		velocity = Vector2.RIGHT * speed 
		is_moving= true
		dir = "right"

	elif Input.is_action_pressed("ui_up"):
		velocity = Vector2.UP * speed
		is_moving= true
		dir = "up"

	elif Input.is_action_pressed("ui_down"):
		velocity = Vector2.DOWN * speed
		is_moving= true
		dir = "down"

	else:
		velocity = Vector2.ZERO
		is_moving = false




	if is_moving == true:
		if Input.is_action_pressed("crouch"):
			if dir == "left":
				velocity = Vector2.LEFT * crouch_spd
				anim.play("walk_left")
			elif dir == "right":
				velocity = Vector2.RIGHT * crouch_spd
				anim.play("walk_right")
			elif dir == "up":
				velocity = Vector2.UP * crouch_spd
				anim.play("walk_up")
			elif dir == "down":
				velocity = Vector2.DOWN * crouch_spd
				anim.play("walk_down")


	move_and_slide()



	if is_moving == true:
		if dir == "left":
			anim.play("walk_left")
		elif dir == "right":
			anim.play("walk_right")
		elif dir == "up":
			anim.play("walk_up")
		elif dir == "down":
			anim.play("walk_down")

	elif is_moving == false:
		if dir == "left":
			anim.play("idle_left")
		elif dir == "right":
			anim.play("idle_right")
		elif dir == "up":
			anim.play("idle_up")
		elif dir == "down":
			anim.play("idle_down")

Thanks!

speed_scale should be on anim, so:

        if Input.is_action_pressed("crouch"):
            anim.speed_scale = 0.5
            [...]
        else:
            anim.speed_scale = 1.0

Tried the same thing to speed up dash animation to 2.0 scale, didn’t see a difference. But the crouch works! Thanks!