Destroy gameObject with Raycast

I get a “NullReferenceException: Object reference not set to an instance of an object” Error, This is what is on the line the error is coming from.

Destroy(hit.transform.gameObject);

This is the block of code that is in

//Destroy
	if(Input.GetMouseButtonDown(1)){
		
		var DestroyPos = Input.mousePosition;
		var DestroyObjectPos = Camera.main.ScreenToWorldPoint(DestroyPos);
		var hit:RaycastHit;
		
		Destroy(hit.transform.gameObject);
	}

I know the problem is with the hit.transform.gameObject, but I don’t know what

Honestly, this is 100% the correct answer based your original question:

I get a “NullReferenceException:
Object reference not set to an
instance of an object” Error, This is
what is on the line the error is
coming from.

Destroy(hit.transform.gameObject);

This is the block of code that is in

//Destroy
if(Input.GetMouseButtonDown(1)){
var DestroyPos = Input.mousePosition;
var DestroyObjectPos = Camera.main.ScreenToWorldPoint(DestroyPos);
var hit:RaycastHit;
Destroy(hit.transform.gameObject);
}

I know the problem is with the
hit.transform.gameObject, but I don’t
know what

You have declared a variable called hit on line 6. The variable is of type RaycastHit and is null. You have not set or initialized the variable whatsoever, when you try and access the transform member, it doesn’t exist, which means gameObject on transform doesn’t exist because hit doesn’t exist(null).

Use something like Physics.RayCast (<- read the documentation for examples) to actually set your hit variable.