Animation not stopping eventhough in code it should stop

Godot Version

Question
hi so i want to go from my walking animation to the idle animation but it does not work and i cannot figure out why

my code:

extends KinematicBody2D

class_name Player


var Gravity = 5
var walk_speed = 60
var jump_height = -50
var JUMP_FORCE = -130
var double_jump = 1
var double_jump_count = 2
var velocity = Vector2.ZERO
onready var animsprite = $AnimatedSprite
onready var animpstate = $AnimatedSprite/AnimationPlayer/AnimationTree.get("parameters/playback")

func _ready():
	state = states.IDLE
	pass
var state
enum states{
	IDLE,
	WALK,
	SHOOT,
	ATTACK
	
	
}


func _physics_process(delta):
	gravity()
	walk()
	match state:	
		states.IDLE:
			animpstate.travel("Idle")
		states.WALK:
			animpstate.travel("Walk")
		states.ATTACK:
			animpstate.travel("Attack")
		states.SHOOT:
			animpstate.travel("Shoot")
	
	
	
	
func walk():
	if Input.is_action_pressed("ui_right"):
		state = states.WALK
		velocity.x = walk_speed
	elif Input.is_action_pressed("ui_left"):
		state = states.WALK
		velocity.x = -60
	else:
		velocity.x = 0
		state = states.IDLE
		
	if velocity.x < 0:
		animsprite.flip_h = true
		$Hitboxposition.rotation_degrees = 180
	elif velocity.x > 0:
		animsprite.flip_h = false
		$Hitboxposition.rotation_degrees = 0
	
	if is_on_floor() or is_on_wall():
		double_jump = double_jump_count		
		if Input.is_action_just_pressed("ui_up"):
			velocity.y = JUMP_FORCE 	

	if Input.is_action_just_pressed("ui_up") and double_jump > 0:
		velocity.y = JUMP_FORCE
		double_jump -= 1
		

	
		
	if  Input.is_action_pressed("ui_right"):
		pass
	
	
func gravity():	
	velocity.y += Gravity
	velocity = move_and_slide(velocity)
	

Check if you have set up the animation tree properly.

hey i checked that changed some things in the animation tree now it stops for a second and goes back to playing again

Can you send a screen shot of the tree?

There is a connection from idle to walk but not from walk to idle, so the animation has to pass shoot to go back to idle.

hi i changed it so walk and idle have two connections still doesnt work

Can you be a bit more specific about how it doesn’t work? I’m sure it’s the animation tree contractions.

so when i walk it goes to the walk animation and when i stop it should go to the idle animation but it doesn’t and goes back to playing the walk animation

Does your idle animation work on its own? I can’t find anything wrong with your code.

yes the idle animation works on its own

To set the idle state you are checking that the velocity.x is neither > 0 or < 0, but velocity.x is a float driven by physics, which means it won’t be zero most of the time. change it to > 1 and < -1 and see what happens.

hi so something like this right
if velocity.x < -1: state = states.IDLE elif velocity.x > 1: state = states.IDLE