Nonexistent function 'Instance' in base 'Nil'.

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

Hello everyone. I’m following this tutorial to make arrows to my game. However, when I try to fire the bow the game crashes and the following error keeps pops 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 =

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

Which line is giving you the error?

SteveSmith | 2022-10-02 07:55

:bust_in_silhouette: Reply From: SteveSmith

It looks like you haven’t set “arrow”. Click on this scene in the editor, and on the right-hand side should be an “arrow” setting, in which you’ll need to select your arrow node.

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

ItzKillerTTV | 2022-10-02 17:41 → bow_end.global_position

SteveSmith | 2022-10-02 17:53