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
time_left -= 1
if 0 >= time_left:
for index in get_slide_count():
	var collision = get_slide_collision(index)
	if collision.collider.is_in_group("enemy"):

		#Want to access "ScriptName" in the collider and the health variable 
inside that -= CharacterSheet.gun_damage
	elif collision.collider.is_in_group("player"):
	elif collision.collider.is_in_group("bullet"):
: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 : -= CharacterSheet.gun_damage
:bust_in_silhouette: Reply From: dacess123

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