Player not getting deleted

Godot Version 4.3

My player character will only get deleted once after death, all other times after that, it will just spawn in another player without removing the previous one. Here is part of the script

@onready var playerone = $PlayerOne
var new_objone

func _on_player_one_respawn_timeout():
	playerone.living = true
	remove_child(playerone)
	new_objone = player_scene.instantiate()
	new_objone.position = $PlayerOneRespawnSpot.position
	get_parent().add_child(new_objone)
	playerone = new_objone
	readytorespawnone = true
func _on_player_one_respawn_timeout():
	playerone.living = true # This does nothing
	remove_child(playerone) # Use queue_free instead
	new_objone = player_scene.instantiate() #I'm assuming this is correct.
	new_objone.position = $PlayerOneRespawnSpot.position #swap with line below
	get_parent().add_child(new_objone) #swap with line above.
	playerone = new_objone
	readytorespawnone = true

See if that works.

1 Like

I should note that this is the level script, and not the character script, when I added the queue free thing, it just went to the player one main scene.

Another suggestion: Use add_sibling() instead of get_parent().add_child().

2 Likes

playerone isn’t a child of this object it’s a sibling, so remove_child(playerone) should produce a error or warning.

Use queue_free instead.

@onready var playerone = $PlayerOne
var new_objone

func _on_player_one_respawn_timeout():
	playerone.living = true
	playerone.queue_free()
1 Like

That works, thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.