Hello, while working on creating another enemy to spawn bullets I ran into an issue I have not faced yet. I did not change the script but now I get the error How can I fix error "Invalid get index 'position' _on base:('null instance'). What does it mean and how in my script can I fix it? Also why did this happen and what can I do to prevent it in the future I was on a role and I don't want to have this happen again.
My code is as follows:
extends Node2D
var bullet_scene = load("res://Bullet.tscn")
onready var player = getparent().getparent().get_node("PLayer")
var type = "Enemy"
func ready():
$Timer.setwait_time(.5)
$Timer.start()
func process(delta):
lookat(getglobalmouse_position())
position.y += 40 * delta
if(position.y > get_viewport_rect().size.y + 20):
get_parent().remove_child(self)
queue_free()
func spawn_bullets():
var b1 = bullet_scene.instance()
b1.position = self.position
b1.dir = Vector2(player.position.x - self.position.x, player.position.y - self.position.y).normalized()
get_parent().add_child(b1)
func timeout():
spawn_bullets()
Thanks!