i need a help i want to change the health of enemy from another script but it doesnt changes it

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

here is the code:

        randomize()
		var damage = rand_range(10.0, 30.0)
		get_node("/root/World/Enemy").health -= damage
	if get_node("/root/World/Enemy").health == 0.0:
		collider.queue_free()
:bust_in_silhouette: Reply From: Spiky_Potato

Well, something you could try is setting the node as a variable. Something like this:

onready var Enemy = get_node("/root/World/Enemy")

Then all you’d have to do is reference the variable and the inner variable as an extension:

randomize()
var damage = rand_range(10, 30)
Enemy.health -= damage
if Enemy.health == 0
  collider.queue_free()

This is at least what I’d try. Hopefully it helps.