State machine seemingly not working

I have a statemachine but for some reason the walking state transitions into the sleeping state despite not even being hooked up to it, I have no idea why that happens

Here’s how it is hooked up

walk.pickup.connect(finite_state_machine.change_state.bind(grabbed))
	walk.becomeidle.connect(finite_state_machine.change_state.bind(idle))
	
	grabbed.becomeidle.connect(finite_state_machine.change_state.bind(idle))
	grabbed.startwalking.connect(finite_state_machine.change_state.bind(walk))
	
	idle.pickup.connect(finite_state_machine.change_state.bind(grabbed))
	idle.startwalking.connect(finite_state_machine.change_state.bind(walk))
	idle.fallsleep.connect(finite_state_machine.change_state.bind(sleep))
	
	sleep.pickup.connect(finite_state_machine.change_state.bind(grabbed))
	sleep.startwalking.connect(finite_state_machine.change_state.bind(walk))

Here’s the state machine

class_name FiniteStateMachine
extends Node

@export var state: State

func _ready():
	change_state(state)
	

func change_state(new_state: State):
	if state is State:
		state._exit_state()
	new_state._enter_state()
	state = new_state

its only supposed to go to sleep if its in the idle state, but for some reason it just skips it and goes to it even while its walking

Walking

signal becomeidle
signal pickup
signal foundfood


func _ready() -> void:
	pickup_area.input_event.connect(_on_input_event)
	timer.timeout.connect(_timerdone)
	set_physics_process(false)

func _on_input_event(viewport: Node, event: InputEvent, shape_idx: int):
	if Input.is_action_pressed("Click") and !Events.blockpickedup:
		pickup.emit()

func _enter_state() -> void:
	animation_player.play("Walk")
	print("startedwalk")
	starttime()
	set_physics_process(true)

func starttime():
	timer.start(randi_range(2,6))


func _timerdone():
	var chance = randi_range(0,100)
	var secondchance = randi_range(0,100)
	if chance <= 60:
		starttime()
	elif chance <=80:
		rotter.speed = -rotter.speed
		sprite_2d.flip_h = !sprite_2d.flip_h
		if secondchance <= 90:
			starttime()
		else:
			becomeidle.emit()
	else:
		becomeidle.emit()

func _exit_state() -> void:
	set_physics_process(false)

func _physics_process(delta) -> void:
	rotter.velocity.x = -rotter.speed
	

Idle state:

signal startwalking
signal pickup
signal foundfood
signal fallsleep

func _ready() -> void:
	pickup_area.input_event.connect(_on_input_event)
	timer.timeout.connect(_timerdone)
	set_physics_process(false)

func _on_input_event(viewport: Node, event: InputEvent, shape_idx: int):
	if Input.is_action_pressed("Click") and !Events.blockpickedup:
		pickup.emit()

func _enter_state() -> void:
	animation_player.play("Wait")
	print("startedidle")
	rotter.velocity = Vector2.ZERO
	starttime()
	set_physics_process(true)

func _exit_state() -> void:
	set_physics_process(false)

func starttime():
	timer.start(randi_range(1,6))

func _timerdone():
	var chance = randi_range(0,100)
	var secondchance = randi_range(0,100)
	if chance <= 25:
		startwalking.emit()
	elif chance <=50:
		rotter.speed = -rotter.speed
		sprite_2d.flip_h = !sprite_2d.flip_h
		if secondchance <= 90:
			startwalking.emit()
		else:
			starttime()
	elif chance <=75:
		starttime()
	else:
		starttime()
		fallsleep.emit()

Sleeping state:

func _ready() -> void:
	pickup_area.input_event.connect(_on_input_event)
	timer.timeout.connect(_timerdone)
	set_physics_process(false)


func _on_input_event(viewport: Node, event: InputEvent, shape_idx: int):
	if Input.is_action_pressed("Click") and !Events.blockpickedup:
		pickup.emit()

func _enter_state() -> void:
	animation_player.play("Sleeping")
	print("startsleeping")
	rotter.velocity = Vector2.ZERO
	starttime()
	set_physics_process(true)


func _exit_state() -> void:
	set_physics_process(false)

func starttime():
	timer.start(randi_range(5,6))

func _timerdone():
	var chance = randi_range(0,100)
	if chance <= 85:
		startwalking.emit()
	else:
		starttime()

i dont know if this will solve your problem or not but maybe you should move the sleeping state logic to the idle state script so its effects can be triggered under certain condtions and then just have the sleeping state script be refrence if it goes beyond the scope of needed it in your idle state script ik it not like the top tier way but it can possibly work i can back to edit thiis because i thought of a better way but im not going to explain sorry

Hmm maybe, well if you do find the time to explain the better way you thought of I’d love to hear it.

Is there any particular reason you aren’t feeling in explaining the alternative solution?

because it could be total wrong but i think with what i suggest last it might provide some type of soultion