• Godot Help
  • Invalid call. Nonexistent function 'Instance' in base 'Nil'.

Hello everyone. I'm following this tutorial to make arrows for my game. However, when I try to fire the bow the game crashes and the following error keeps popping up:

"Invalid call. Nonexistent function 'Instance' in base 'Nil'."

The guy in the video is attaching his script to KinematicBody2D Player, but I want the bow my character uses to move with the mouse, so I'm assigning this script to the bow.

Any ideas on how to fix this? I am new to programming in general, so you'd help me a lot. Thanks in advance.

This is my code:

extends Node2D

onready var bow_end = $BowEnd
onready var bow_cooldown = $Bowcooldown

export (PackedScene) var arrow

func _process(_delta): 
        look_at(get_global_mouse_position())

func _unhandled_input(event: InputEvent) -> void: 
        if Input.is_action_just_pressed("ui_attack") and is_visible_in_tree(): 
        shoot()

func shoot(): 
        var arrow_instance = arrow.instance() 
        add_child(arrow_instance) 
        arrow_instance.global_position = bow_end.global.position

If any more information is needed, I'll be happy to provide it.

    ItzKillerTTV var arrow_instance = arrow.instance()

    Is that the line that's causing the error?

    Did you populate the arrow property with the arrow scene in the Inspector?

    (I didn't watch the video.)

      DaveTheCoder That was indeed the issue, thank you so much. However, now the next line is the problem. The issue changed to "Invalid get index 'global' (on base:'Position2D')." Any ideas?