HeadShot Script Help

I made a script to simulate a headshot and it has errors and i dont know how to fix it... can someone help?

var hitSound : AudioClip;
var DMGheight1 = 12.0;
var apply : boolean = true;
var Character : AI;
private var collisionMagnitude : float;
var HeadShots : float;

killed = false;

function OnCollisionEnter (hit : Collision) {
    if (apply == true) {
        if (hit.relativeVelocity.magnitude >= DMGheight1) {
            collisionMagnitude = hit.relativeVelocity.magnitude;

        if (hit) {
            audio.PlayOneShot(hitSound, 0.5);

function ApplyDamage (damage : float) {
    // We already have less than 0 hitpoints, maybe we got killed already?
    if (Character != null) {
        Character.SendMessage("ApplyDamage", collisionMagnitude * 2);
    if (Character == null) {

function Destroy (killed : boolean) {
    if (killed == true) {
    else {

the logic of your code could not be understood easily but you called sendMessage for a function in itself without calling it from another function so should it be called? what does not work? does the collision works, if yes the logic of this code is something that does not work (which i think is the problem).

there are other things like if(hit), as i know hit is a struct with some info so what does it mean to have it in an if statement? again your sendmessage will not be never called because you should put it in OnCollision with it's condition. applyDamage will not be ever called to send this message to call itself again!

my description is based on the part of your code that you posted but you might have done other things in other parts of your code that i don't know about them and they add to wrongness of this logic.