Keep on getting previously freed

extends Node2D

var speed = 100
var player_chase = false
var player = null

var health = 100
var player_inattack_zone = false

func _physics_process(delta):
deal_with_damage()

if player_chase:
	position += (player.position - position)/speed

	$AnimatedSprite2D.play("walk")
	
	if(player.position.x - position.x) < 0:
		$AnimatedSprite2D.flip_h = true
	else:
		$AnimatedSprite2D.flip_h = false
else:
	$AnimatedSprite2D.play("idle")

func _on_detection_area_body_entered(body):
player = body
player_chase = true

func _on_detection_area_body_exited(_body):
player = null
player_chase = false

func enemy():
pass

func _on_enemy_hitbox_body_entered(body):
if body.has_method(“player”):
player_inattack_zone = true

func _on_enemy_hitbox_body_exited(body):
if body.has_method(“player”):
player_inattack_zone = false

func deal_with_damage():
if player_inattack_zone and Global.player_current_attack == true:
health = health - 20
print("slime health = ",health)
if health <= 0:
self.queue_free()
what’s wrong with this code?

Can you provide a description on what you are trying to achieve, what exact error you are getting and what steps do you previously took to try and solve the issue.

We need more context.

Can you please format your code using the button in the toolbar…

I agree with the others on code formatting and explaining your issue more thoroughly, you could try putting deal_with_damage at the end of _physics_process as maybe it’s queue free and running the rest of that code? But I think it’s more of a race condition than that.