Experience Script Problem

I am trying to make a simple experience script that when the enemy dies he rewards my player with 50 exp but when the enemy dies it is not giving my character any experience. I get the following error when my enemy dies.

NullReferenceException: Object reference not set to an instance of an object
EnemyHealth.Experience () (at Assets/Scripts/EnemyHealth.js:27)
EnemyHealth.Dead () (at Assets/Scripts/EnemyHealth.js:21)
EnemyHealth.Update () (at Assets/Scripts/EnemyHealth.js:9)

ExperienceScript

var currentExperience : int;
var maxExperience : int = 100;

function GiveExperience ()
{
	var experienceGain = EnemyHealth.experienceGain;
	currentExperience += experienceGain;
	if(currentExperience >= maxExperience)
	{
		Debug.Log("LEVEL UP!");
	}
}

EnemyHealth

var Health = 100;
static var experienceGain : float = 50;

function Update ()
{
	if(Health <= 0)
	{
		Dead();
	}
}

function ApplyDamage (Damage : int)		
{
	Health -= Damage;
}

function Dead ()
{
	Destroy(gameObject);
	Experience();
}

function Experience ()
{
	var experienceScript : ExperienceScript;
	experienceScript.GiveExperience();
}

When you declare a variable, it is by default, null.

At line 25, you declare the variable experienceScript but it is not assigned. Therefore, when you try to call a function in line 26, it throws a null exception.

I have tried changing that line of code and i added in a Debug.Log(“You Gained Experience”); into the GiveExperience function to see if it was working and its not.

Do you have any ideas on how i can call the GiveExperience on my ExperienceScript through the Experience function on my EnemyHealth script.

in Dead() you destroy the current gameObject (and all the scripts/components attached to it) then you try to call a function within the script (which you just destroyed so it doesn’t exist)… try that code other way around, do the experience first, then destroy the gameObject.