Accessing Variable From Other Gameobject

Ok so I was hoping that when these to objects go collide or in my case enter trigger that they roll a dice and which ever is lower it gets deleted! Here my code.

#pragma strict
var Dice = 0;
Dice = Random.Range(1,100);
private var anotherScript : SunDele;

function OnTriggerEnter(slr : Collider) {
  anotherScript = slr.GetComponent(SunDele);
  if (anotherScript.Dice > Dice) {
    Destroy (gameObject.transform.parent.gameObject);
  }
}

Now I have put rigedbody on both and enabled trigger enter but I get the error: NullReferenceException: Object reference not set to an instance of an object SunDele.OnTriggerEnter (UnityEngine.Collider slf) (at Assest/SunDele.js:8)
However it did do what I wanted it to do (I can see through the editor) but it pause the game and gives me that error. plz help

Edit: looks like line numbering is 1 indexed rather than 0 indexed, so the error line would actually be:

if (anotherScript.Dice > Dice) {

This means that anotherScript is null, which means that there isn’t a SunDele script on the collider that entered the trigger. If you change it to:

if (anotherScript != null && anotherScript.Dice > Dice) {

Then it will do nothing when a collider without the script enters the trigger, and it will do what you want it to when a collider with the script enters.

Also, on this line:

Destroy (gameObject.transform.parent.gameObject);

The first reference to gameObject is useless, you could just have:

Destroy (transform.parent.gameObject);