Timer not counting down

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

I’m having issues with a timer not counting down when running my project. Here is the code, perhaps I’m doing something obviously wrong but I can’t see it :slight_smile:


Player.gd

var weapon_scene = preload("res://scenes/Weapon.tscn")
var weapon = weapon_scene.instance()

func _process(delta):
    if Input.is_action_pressed("fire"):
        weapon.fire()

Weapon.gd

(Weapon.tscn has a timer named CooldownTimer with one-shot set to true and wait time 1 second)

func fire():
    if $CooldownTimer.is_stopped():
        $CooldownTimer.start()
        print('Firing!')
    else:
        print("cooldown...", $CooldownTimer.get_time_left())`

Seems pretty straightforward, but the first time I press the key says “Firing!” and every time after I get “cooldown…1”
I also added a callback on the timer’s cooldown and it never gets fired.

Thanks in advance if you can tell me whats wrong :slight_smile:

:bust_in_silhouette: Reply From: Leander

Alright, I found the issue.

I forgot to add the Weapon node to the Player, eg.

Player.gd

func _ready():
    add_child(weapon)

So… oops! Well everybody does it once, right? :slight_smile: