Hello guys. I am getting the above error when I am playing my game. Everything works fine when I fire the bullets on my enemy but for some reason when the health bar on enemy gets depleted I get the error mentioned above. I have scene named 'Enemy' and within it I have instanced another scene named 'Health' which contains the ProgressBar with the Script. I have created a variable named 'hp' in Enemy Script but I m not sure that why things are not working out with the Life Bar. This is the what I am using to actually get the value of 'hp' in the value of Life Bar:
extends ProgressBar
func _ready():
pass
func _physics_process(delta):
value=get_tree().root.get_node("World").get_node("Enemy").hp
and this is my dead function in 'Enemy' Script :
func dead():
hp-=1
if hp<=0:
is_dead=true
velocity=Vector2(0,0)
$AnimatedSprite.play("Dead")
$CollisionShape2D.disabled=true
$Timer.start()
As I mentioned earlier, for some reason when the health bar of my enemy is getting depleted I am getting the error invalid get instance 'hp' (on base: 'null instance') and my game freezes.