Problems with the signals...again

Godot Version

4.2.1

Question

Hello everybody! I’m making a trap block, it should disappear after 3 seconds (conditionally) and appear after 4 seconds (conditionally), but I can’t figure out who to send the signal to, also the IDE swears at the last line.

extends RigidBody2D

var disappear_time: float = 1.0

var respawn_time: float = 4.0

var is_active: bool = true

var spawn_position: Vector2

func _on_Area2D_body_entered(body):
	if is_active:  
		is_active = false
		spawn_position = position  
		await get_tree().create_timer(disappear_time).timeout
		queue_free()  
		
		await get_tree().create_timer(respawn_time).timeout
		respawn()

func respawn():
	var new_block = preload("res://Scenes/Death_block.tscn").instantiate()  
	new_block.position = spawn_position  
	get_parent().add_child(new_block)  

func _ready():
    connect("body_entered", self, "_on_RigidBody2D_body_entered")

since you are in godot 4 you can use the easier syntax in your ready-method:

func _ready():
	body_entered.connect(_on_RigidBody2D_body_entered)

This should also help you find the problem.

Here you are deleting your node and then try to run code after it, which doesnt make sense, since at this point your node doesnt exist anymore:

		await get_tree().create_timer(disappear_time).timeout
		queue_free()  # <- Here it gets deleted
		
		# The following lines wont be executed
		await get_tree().create_timer(respawn_time).timeout
		respawn()