Duplicated collision event problem

Godot Version

4.2

Question

Hey, I’m struggling with problem with duplicated collision event. I have top down shooter game, where player can shoot projectiles and enemies can shoot projectiles. Enemies and player are shooting with the same projectile scene. I tried to create an interaction where after projectile collides with another projectile, they are destroyed and explosion scene is spawned. So I prepared code for my projectile:

func onCollisionWithArea(area):
	if area is Projectile and area.targetGroup != targetGroup:
		area.destroy()
		explode()
		destroy()

func destroy():
	if is_instance_valid(self):
		hide()
		queue_free()
		
func explode():
	if exploded:
		return
	exploded = true
	var explosion = explosionScene.instantiate()
	explosion.damage = damage
	explosion.targetGroup = targetGroup
	explosion.global_position = global_position
	get_tree().root.add_child(explosion)

Sometimes race condition makes the explosion spawning twice (one time from one projectile, second time from second projectile). Do exist some smart way to prevent it from happening?

well, because both has the same script, so both will explode