When a character dies the turn manager freezes

Godot Version

v4.2.2.stable

Hi, the problem I have with the turn manager is when one of the 4 players dies, he’s removed from the characters array and what was his turn arrives, stops and doesn’t continue to the next ones, although I can continue opening the pause menu, so It hasn’t crashed, it only happens when one of the players dies, with enemies it works perfectly and godot does not detect any errors.

this is the script

class_name Turn_orden
extends Node

var characters: Array = []   #(players y enemies)
var current_turn_index: int = 0 

@onready var act_per_turn_ui: ActPTurnUI = $"../BattleUI/ActPerTurnUI"

@onready var name_skill_label: Label = %Name_skill_Label

@onready var player_group: Node2D = $PlayerGroup
@onready var enemy_handler: EnemyHandler = $EnemyHandler as EnemyHandler
@onready var player_handler: PlayerHandler = $"../PlayerHandeler"
@onready var turn_panel: Panel = $"../BattleOverLayer/TurnPanel"
@onready var turn_label: Label = $"../BattleOverLayer/TurnPanel/TurnLabel"
@onready var group_enemy: TextureRect = %GroupEnemyTexture
@onready var combat_text: Label = %CombatTextLabel

var round_comb: int = 1

func _ready():
	Events.enemy_died.connect(_on_remove_character)
	Events.player_died.connect(_on_remove_character)
	Events.enemy_single_turn.connect(end_turn)

	_load_characters()
	sort_characters_by_speed()
	
	start_turns()

func _load_characters():
	characters.clear()
	
	for child in enemy_handler.get_children():
		if child is Enemy:
			characters.append(child)

	for child in player_group.get_children():
		if child is Player:
			characters.append(child)
				
func sort_characters_by_speed():
	characters.sort_custom(_compare_speed)
	var names = []
	for character in characters:
		names.append(character.stats.name)
	print("Turno ordenado por velocidad: %s" % str(names))

func _compare_speed(a, b) -> int:
	return a.stats.speed > b.stats.speed 

func start_turns():
	if characters.size() == 0:
		return
	
	sort_characters_by_speed()
	
	print(current_turn_index)
	var current_character = characters[current_turn_index]

	print(characters[current_turn_index])

	if current_turn_index == 0:
		print("Ronda: ", round_comb)
		turn_panel.show()
		turn_label.text = str("Ronda %s" % round_comb)
		await get_tree().create_timer(1.5).timeout
		turn_panel.hide()
		
	if current_character is Player:
		player_handler.start_turn(current_character.stats)
		if act_per_turn_ui:
			name_skill_label.text = str(current_character.stats.name)
			act_per_turn_ui.char_stats = current_character.stats
	elif current_character.is_in_group("enemies"):
		enemy_handler.start_turn()
		
	print("Turno de: %s, "  % str(current_character.stats.speed), current_character.stats.name)

func end_turn():
	if characters.size() == 0:
		return
	
	current_turn_index = (current_turn_index + 1) % characters.size()
	
	if current_turn_index == 0:
		round_comb += 1
	
	start_turns()

func _on_remove_character(character: Node) -> void:
	var removed_index = characters.find(character)      
	
	sort_characters_by_speed() 
	
	if removed_index != -1:
		characters.erase(character)
	
		if removed_index < current_turn_index:
			current_turn_index -= 1
		
		if current_turn_index < 0:
			current_turn_index = 0
		
		elif current_turn_index >= characters.size():
			current_turn_index = characters.size() - 1

		print("Personaje eliminado, el nuevo índice de turno es: %d" % current_turn_index)

func _on_end_turn_button_pressed() -> void:
	player_handler.end_turn()
	end_turn()