I think this might be your problem:
if Input.is_action_pressed("ui_right"):
motion.x += ACCEL
facing_right = true
$AnimationPlayer.play("run")
elif Input.is_action_pressed("ui_left"):
motion.x -= ACCEL
facing_right = false
$AnimationPlayer.play("run")
else:
motion.x = lerp(motion.x,0,0.2)
$AnimationPlayer.play("idle")
Its the else statement. It states that if your not walking left or right, to play the idle animation. I suggest that within the else statement you write:
else:
if is_on_floor():
motion.x = lerp(motion.x,0,0.2)
$AnimationPlayer.play("idle")
and see if this fixes it. :)