What is wrong with my script?

I’m getting a: NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (IConvertible convertible)
Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (System.Object value)
Boo.Lang.Runtime.RuntimeServices.UnboxSingle (System.Object value)
MapGrid.Drill () (at Assets/Scripts/MapGrid.js:44)
MapGrid.Update () (at Assets/Scripts/MapGrid.js:39). And my script is not working. Can someone give me a hint what is wrong?

var prefab : GameObject;
var player : GameObject;
var gridX = 5;
var gridY = 5;
private var spacing = 1;
var UseSpawner : boolean = true;
var Spawn : GameObject;

var gridXRounded;
var SpawnX;
var SpawnY;
var block : GameObject;

function Start () 
{
	grid2D = new GameObject[gridX,gridY];
	for (var y = 0; y < gridY; y++){
		for (var x = 0; x < gridX; x++){
			var pos : Vector3 = Vector3(x,y,0) * spacing;
			var newBlock : GameObject = Instantiate(prefab, pos, Quaternion.identity);
			newBlock.name = "GridBlock" + x + "-" + y;

		}
	}
			
	if(UseSpawner){
		var SpawnX : int = Mathf.Round(gridX / 2 - 1);
		var SpawnY : float = gridY + 0.5;

		player.transform.localScale = Vector3(0.75, 0.75, 0.75);
		Spawn.transform.position = Vector3(SpawnX, SpawnY, 0 );
		player.transform.position = Vector3(SpawnX, SpawnY, 0);
	}
}

function Update() {
	if(Input.GetButton("Down")){
		Drill();
	}
}
	
function Drill(){
	block = GameObject.Find("GridBlock" + Mathf.Round(player.transform.x) + "-" + Mathf.Round(player.transform.y - 1));
	Destroy(block);
}

It would seem that ‘block’ is null inside your ‘Drill’ method. Put a break point on line line 44 and check it’s value. It may be that your character is attempting to drill at a location where there is no block to destroy, thus you should add a sanity check inside your ‘Drill’ method:

function Drill()
{
    block = GameObject.Find("GridBlock" + Mathf.Round(player.transform.x) + "-" + Mathf.Round(player.transform.y - 1));

    if(block != null)
        Destroy(block);
}

EDIT 1:

It also looks like your ‘player’ object may be null as your script doesn’t assign it anywhere in the code you provided. You should assign it in the ‘Start’ method.

EDIT 2:

Further inspection makes me think that you need to cast your float values to ints as you seem to have used ints when naming the blocks. Line 44 should look like:

block = GameObject.Find("GridBlock" + parseInt(Mathf.Round(player.transform.x)) + "-" + parseInt(Mathf.Round(player.transform.y - 1)));