NullReferenceException: Object reference not set to an instance of an object

#pragma strict
import System.Collections.Generic;

var loot : ItemClass[];
var Inventory : Inventory;
function Start () {
Inventory = GetComponent("Inventory") as Inventory;
}
function OnGUI()
{
GUILayout.BeginArea(Rect(0,0,500,050));
if(GUILayout.Button("Loot!"))
		{
		
		Giveloot();
			
		}
GUILayout.EndArea();
		
}

function Giveloot(){

for(var x = 0; x < loot.length; x++){
Inventory.PlayerInventory.Add(loot[x]);
}

}

I have this script, but it keeps saying NullReferenceException: Object reference not set to an instance of an object. I dont know whats wrong. All anwsers are appresiated.

Hi!

You don’t tell us everything. The only action it can do, is to call Giveloot when you push the button “Loot!”.

If the problem appears when you click on “Loot!”, then the issue is simple,
you didn’t allocated loot.

Add in Start()

look = new ItemClass[X]; // With X your count