Can't get my sprint to work?

Godot 4.3

func _physics_process(delta):
	var direction = Input.get_vector("move_left", "move_right", 
	"move_up", "move_down")
	velocity = direction * 600
	move_and_slide()
	if velocity.length() > 0.0:
		%HappyBoo.play_walk_animation()
	else:
		%HappyBoo.play_idle_animation()
	if Input.is_action_pressed("sprint"):
		velocity = direction * 750
	elif Input.is_action_just_released("sprint"):
		velocity = direction * 600
	

i am trying to make a sprint but i can’t get it to work, i did get the sprint working earlier but once i got it working the animation for my sprite broke and when i got the animation working again the sprint broke.

Notice the order of your operations, you must apply all of your speed effects before move and slide

  1. set velocity to direction * 600
  2. use move_and_slide() to finalize the velocity’s effect and move at 600 speed
  3. play animation
  4. if sprint held, set velocity to direction * 750

thank you it works perfectly now