2d topdown animations playing in the middle of each other & also some flickers

Godot Version

4.3

Question

`Hi, Im learning to make a 2d topdown rpg game and for the main character’s animations im using animation player&animation tree and i tried lot in the codes to stop player transitioning to different animations at the same time but still like when im in the middle of rolling if i attack it just switches (which i dont want) and also when im attacking right if at the end i look up a frame of attack animation again plays (like a flicker), whats the problem with these two?

my character codes :

extends CharacterBody2D
 
@export var ACCELERATION = 800
@export var FRICTION = 600
@export var MAX_SPEED = 120
@export var ROLL_SPEED = 140

@onready var animationTree = $AnimationTree
@onready var animationState = animationTree.get("parameters/playback")
@onready var swordHitbox = $Hitboxpivot/SwordHitbox
var playing = false
enum{
	MOVE , 
	ROLL ,
	ATTACK
}
var state = MOVE
var roll_vector = Vector2.ZERO
func _ready() -> void:
	$Hitboxpivot/SwordHitbox/CollisionShape2D.disabled = true
	swordHitbox.knockback_vector = roll_vector
func _physics_process(delta: float) -> void:
	if Input.is_action_just_pressed("Attack"):
		state = ATTACK
	elif Input.is_action_just_pressed("Roll") and canRoll():
		state = ROLL
	if playing == false:
		match state:
			MOVE:
				MoveState(delta)
			ROLL:
				rollState(delta)
			ATTACK:
				attackState(delta)

func MoveState(delta):
	$Hitboxpivot/SwordHitbox/CollisionShape2D.disabled = true
	var input_vector = Input.get_vector("Move_Left" , "Move_Right" , "Move_Up" , "Move_Down")
	if input_vector != Vector2.ZERO:
		roll_vector = input_vector
		swordHitbox.knockback_vector = roll_vector
		animationTree.set("parameters/Idle/blend_position" , input_vector)
		animationTree.set("parameters/Run/blend_position" , input_vector)
		animationTree.set("parameters/Attack/blend_position" , input_vector)
		animationTree.set("parameters/Roll/blend_position" , input_vector)
		animationState.travel("Run")
		apply_movement(input_vector*ACCELERATION*delta)
	else:
		animationState.travel("Idle")
		apply_friction(FRICTION*delta)
	move()

func apply_friction(amount) -> void:
	if velocity.length() > amount:
		velocity -= velocity.normalized() * amount
	else:
		velocity = Vector2.ZERO
		
func apply_movement(amount) -> void:
	velocity += amount
	velocity = velocity.limit_length(MAX_SPEED)

func attackState(delta) -> void:
	velocity = Vector2.ZERO
	animationState.travel("Attack")
	await get_tree().create_timer(0.4).timeout
	state = MOVE
func rollState(delta):
	animationState.travel("Roll")
	velocity = roll_vector*ROLL_SPEED
	move()
func move():
	move_and_slide()
func canRoll() -> bool:
	if velocity.x > 100 or velocity.x < -100:
		return true
	elif velocity.y > 100 or velocity.y < -100:
		return true
	else:
		return false
func on_attack_finished():
	state = MOVE
func on_roll_finished():
	velocity = velocity*0.9
	state = MOVE


func _on_animation_tree_animation_player_changed() -> void:
	playing = true
func _on_animation_tree_animation_finished(anim_name: StringName) -> void:
	playing = false

`