What is wrong with this code,,,

Godot Version

3.5v

Question

Hi i am making enemy and everything is working except the HP is not updating in game the textureprogress just float above enemy and dont change. here is the code :

extends KinematicBody2D

var motion = Vector2()
var state = 0
var hore = false
var dole = false
var maxHealth : int = 100
var HP : int = 100
var player = null
var speed = 45
var healthBar : TextureProgress

func _ready():
if healthBar:
healthBar.max_value = maxHealth
healthBar.value = HP

func _physics_process(delta):
if HP < 1 :
queue_free()

if player ==null:

	if state ==0:
		motion.x=0
		motion.y=0
		$AnimatedSprite.play("idle down")
	elif state ==1:
		motion.x=15
		motion.y=0
		
		$AnimatedSprite.play("walk right")
	elif state ==2:
		motion.x=-15
		motion.y=0
		$AnimatedSprite.play("walk left")
	elif state==3:
		motion.y=15
		motion.x=0
		$AnimatedSprite.play("walk down")
	elif state==4:
		motion.y=-15
		motion.x=0
		$AnimatedSprite.play("walk up")
		
	move_and_slide(motion, Vector2(0,-1)) 
else:

	motion = Vector2.ZERO
	if player:
		motion = position.direction_to(player.position) * speed
	motion = move_and_slide(motion)	
	if motion != Vector2.ZERO:
		if motion.y>0:
			$AnimatedSprite.play("walk down")
		if motion.y<0:
			$AnimatedSprite.play("walk up")

func update_health_bar():
if healthBar:
healthBar.value = float(HP) / maxHealth

func _on_Timer_timeout():
state = floor(rand_range(0,5))

func _on_detection_area_body_entered(body):
player = body

func _on_detection_area_body_exited(body):
player = null

func _on_Area2D_area_entered(area):
HP = clamp(HP - 10, 0, maxHealth)
update_health_bar()
print(HP)

thanks for any help

you dont reference the healthBar, but you want to use it, also you put if healthBar line of code, which mean it should not accessed the following code because it’s null, so the healthBar will never be updated
to fix, use

export var healthBar : TextureProgress

then put the healthBar TextureProgress Node to inspector dock