Please please i need help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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

the root is Swim_demo
Platforms
Area2D
Door
Key
Exit
HUD
COINS/coin1 coin2
Adventure(camer2D)
COCONUTS/coconut

Swim_demo Script
onready var coconuts = 0
onready var hud2 = preload(“res://Scene/HUD2.tscn”)

func _on_Blue_key_body_entered(body):
$Door/Blue_door.queue_free()
$Key/Blue_key.queue_free()

func _on_Gold_key_body_entered(body):
$Door/Gold_door.queue_free()
$Key/Gold_key.queue_free()
add_hud()
remove_hud()

func _on_Green_key_body_entered(body):
$Door/Green_door.queue_free()
$Key/Green_key.queue_free()

func _on_Orange_key_body_entered(body):
$Door/Orange_door.queue_free()
$Key/Orange_key.queue_free()

func remove_hud():
$HUD.queue_free()

func add_hud():
var h = hud2.instance()
add_child(h)

coin1 (and coin2) script
signal coin_collected

func _on_coin_body_entered(body):
$AnimationPlayer.play(“bounce”)
emit_signal(“coin_collected”)
set_collision_mask_bit(0, false)

func _on_AnimationPlayer_animation_finished(anim_name):
queue_free()

coconut script
signal coconut_collected

func _on_AnimationPlayer_animation_finished(anim_name):
queue_free()

func _on_CoCONUT_body_entered(body):
$AnimationPlayer.play(“bounce”)
emit_signal(“coconut_collected”)
set_collision_mask_bit(0, false)

HUD 2 script
var coconuts = 0
var rng = RandomNumberGenerator.new()

func _ready():
$Coconut.text = String(coconuts)

func _physics_process(delta):
if coconuts == 3:
pass

func _on_coconut_collected():
coconuts = coconuts + 1
_ready()

here is what i need help with (please please include code)
so far i have $COCONUTS/coconut1.connect(“coconut_collected”)

i have tried every way i can think to get to the _on_coconut_collected (which is in HUD script)

:bust_in_silhouette: Reply From: Gluon

You dont seem to have really explained your problem so I am assuming what you are trying to do is get the function on_coconut_collected in the hud script to run when the signal coconut_collected is sent.

If this is correct what you need to do is connect the signal you are emitting in the hud script, you would do it by putting this in the ready function of the hud script

connect("coconut_collected", self, "on_coconut_collected")

what this will do is when the signal is sent the hud script will listen out for it and connect to the function you specify.

:bust_in_silhouette: Reply From: alexp

$COCONUTS/coconut1/connect("coconut_collected", self, "_on_coconut_collected")

In the future please try to summarize your problem in the question title, and make your code easier to read by highlighting it and pressing Ctrl+K or clicking the {} button at the top of the text box.

You’re probably better off calling connect inside the coconut script, so that HUD doesn’t have to find all the coconuts itself.

connect("coconut_collected", hud, "_on_coconut_collected") where hud is the reference to your HUD node