Figured it out. Create a singleton and name it Global and give it a var. Name the var enemy__life = 1. Then in your enemy script create a _process function and write:
if Global.enemy_life <= 0:
self.queue__free
Now all you'll need to do is create another function that will subtract from Global.enemy__life. And that's it you are done :)
for those that just wanna see the code here you go!
Enemy:
extends Node2D
export var dialog = ["This is test dialog" , "this is new dialog"]
var character_name : String = "Enemy"
var lvl : int = 2
var dialog_index = 0
var dialog_fin = false
var can_speak = false
func _process(_delta):
if can_speak == true:
load_dialog()
if Global.enemy_life <= 0:
dead()
func load_dialog():
pass
func dead():
Global.enemy_life -= 1
self.queue_free()
func _on_Area2D_area_entered(_area: Area2D) -> void:
can_speak = true
func _on_Area2D_area_exited(_area: Area2D) -> void:
can_speak = false
func _on_Enemy_battle_enemy_died() -> void:
dead()
Just a note but, this code will effect every single enemy that uses this Global value. Regardless if you killed them or not. So you may want to either use this for special occasions or make an export var so every enemy has their own life values.
Happy coding everyone and Farewell!