Acces script when detecting a collision

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

Hey all I’m using the script below for a bullet in my game, however when detecting an enemy I want to remove some of it’s HP, but nothing worked I tried. I want to access the script attached to the collider then a variable inside that script.

extends KinematicBody2D
var speed = CharacterSheet.gun_bullet_speed
var bruuuuh
var time_left = 100
func _physics_process(delta):
bruuuuh = speed * transform.x
move_and_slide(bruuuuh)
time_left -= 1
if 0 >= time_left:
	queue_free()
for index in get_slide_count():
	var collision = get_slide_collision(index)
	if collision.collider.is_in_group("enemy"):
		pass
		

		#Want to access "ScriptName" in the collider and the health variable 
inside that
		collision.collider.ScriptName.health -= CharacterSheet.gun_damage
		queue_free()
		
		
	elif collision.collider.is_in_group("player"):
		print("stuff")
	elif collision.collider.is_in_group("bullet"):
		pass
	else:
		queue_free()
:bust_in_silhouette: Reply From: Inces

collider represents a reference to the colliding node itself, You can get its script properties straight from that reference. You don’t need any reference nor path to script itself. So :

collider.health -= CharacterSheet.gun_damage
:bust_in_silhouette: Reply From: dacess123

If you’re sure that the collider has the variable health then a simple collider.health should give you access