Nonexistent function 'instance' in base 'Nil' error.

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

I’am beginer and trying to understand gdsript code and learning to code.
In past i’ve completed gdspript online free course, so i know some basics but still my learing is not fully complete. I was watching the 2d shooter tutorial and followed the tutorial and i’ve get this error :
Invalid call. Nonexistent function ‘instance’ in base ‘Nil’.
I’ve readed some docs about some contiguous functions and things like that, and wasn’t fonud the solution.
So if there is somone who can help me, i will be greatfull.

extends KinematicBody2D

export  (int) var speed = 150

onready var endOfGun = $endOfGun

var move = Vector2()

export (PackedScene) var bullet

func _ready() -> void:
	pass


func _physics_process(delta: float) -> void:
	var movement_direction := Vector2.ZERO
	if Input.is_action_pressed("up"):
		movement_direction.y = -1
	elif Input.is_action_pressed("down"):
		movement_direction.y = 1
	if Input.is_action_pressed("left"):
		movement_direction.x = -1
	elif Input.is_action_pressed("right"):
		movement_direction.x = 1
	movement_direction = movement_direction.normalized()
	move = move_and_slide(movement_direction* speed)
	
	look_at(get_global_mouse_position())
	


func _unhandled_input(event: InputEvent) -> void:
	if event.is_action_pressed("fire"):
		fire()

func fire():
	var Bullet_instance = bullet.instance()
	add_child(Bullet_instance)
	Bullet_instance.global_position = endOfGun.global_position
	var target = get_global_mouse_position()
	var direction_to_mouse = Bullet_instance.global_position.direction_to(target).mormalize()
	Bullet_instance.set_direction(direction_to_mouse)


func kill():
	get_tree().reload_current_scene()

func _on_Area2D_body_entered(body):
	if "enemy" in body.name:
		kill()
:bust_in_silhouette: Reply From: HyperlinkYourHeart

Your bullet export is not set to anything when the fire function is called. Did you populate it in the inspector?