.connect not working properly for my custom signal

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By cardboard_bones

So I have a Raycast that when it detects the player, it emits a signal called “crossed_line” (for a racing game). I followed the directions of many tutorials to create the following code:
in the Raycast script:

signal crossed_line

func _on_Area_body_entered(body: Node) -> void:
emit_signal("crossed_line")
print ("nice")

func _on_WallDetector_crossed_line():
print ("AH")

and in the Player script

func _ready() -> void:
var wall = get_node("/Main/Path2D/follow/WallDetector")
wall.connect("crossed_line", self, "handle_crossed_line") 

func handle_crossed_line() -> void:
print ("I crossed the line!")

This is exactly the format I see multiple tutorials have you do, however I get an error in the player script that says “Attempt to call function ‘connect’ in base “null instance” on a null instance.”

When I delete the player script and run the game, the game does print “nice” and “AH” whenever the player crosses the line, so I know that the raycast2d works and that the signal works.

I am also positive that the path to the node is correct.

I am not sure what I could be doing wrong, though I know it’s something…any help would be greatly appreciated!

:bust_in_silhouette: Reply From: Chlipouni

I’m not sure but just an idea to help :
It seems that the WallDetector node has not yet entered the tree when you reference it in the ready function of the Player script.
Try to reorder the nodes in the tree.