0 votes

How do you fix an "Invalid get index 'value' (on base: 'null instance')" debug return in the code:

func _on_Area2D_body_entered(body): #connected signal
    if body.get_name() == "Character":
        $HealthBar.value -= 15 

The $HealthBar is a TextureProgress node and I am trying to decrease its value when the main character of my game enters the enemy's area2d. I'm not sure why this code keeps returning as a null instance.
Thank you for helping

in Engine by (17 points)

1 Answer

+2 votes
Best answer

$HealthBar is not accessable from this script.
$HealthBar must be a direct child of the node with this script to access it like so.

by (4,084 points)
selected by

Oh ok, thank you! So, how would you code the change in value for my HealthBar from the other script (it is on the basis that the character enters the enemy's area2d and hence loses some of its health). Thank you again!

read about nodePath's here


you could use something like get_node("/root/baseNodeName/myProgressBar")

Thank you for your help!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.