Need help getting over the hump with a combat script

So a few days ago I was trying to figure out a combat system tutorial, and it never really worked out. Then I started getting excited about coding since thank God I was able to learn how to write a couple of simple codes and modify a few others. Decided to try and write a combat script, and think I’m close, but am humbly asking for help getting over the hump. Here’s how I see it working:

Code A attaches to the sword. When the sword collides with something tagged “enemy” it takes off a certain amount of the enemy’s health.

Code B is attached to the enemy, (actually is attached to an empty game object that the enemy is a child of) and is simply a variable stating said enemy’s health.

I am aware that either code may not be complete, may be sloppy, etc. Trial and error, as I’m so new to this. And help is greatly appreciated. Thanks, and God bless.

Code A:

function onCollisionEnter(Collision)
{

target = GameObject.FindWithTag("Enemy").transform;
     
}

function Update () {
  
}this.enemyHealth -=50;
     
if(this.enemyHealth <= 0) {
    
Destroy(this.gameObject);
     
    
     
     
}

Code B:

var enemyHealth : int = 100;

You should probably switch the scripting around a little bit. Your sword itself does not necessarily even need a script unless you want to control more things like it can only hit once per attack.

So here’s an example of the EnemyScript:

float enemyHealth;
bool enemyDeadBool;



void Start()
{
enemyHealth = 100;
enemyDeadBool = false;
}

void OnTriggerEnter(Collider triggerObject)
{

//assuming the sword object is named sword
if (triggerObject.gameObject.name == "sword")
{
enemyHealth += - 50;	
}

}

void Update()
{
if (enemyHealth <= 0)
{
//may be useful to not just instantly destroy
//you can add +experience or death animation etc...
enemyDead = true;
}

if (enemyDeadBool == true)
{
//do anything to reward player or death animations etc...
Destroy(gameObject);
}



}

Just make sure the sword has a rigid body attached to it and some kind of kinematic collider for the sword using no gravity and set option “Is Trigger” = true;

This will allow your sword to hit the enemy and trigger the enemy health to go down.