how to change FoV

so when i try to change fov with script i get some null error, here’s the script:

var mainCam : Camera;
var normalPos : Vector3;
var aimPos : Vector3;
var weapon : GameObject;

function Start()
{
	mainCam = Camera.main;
}

function Update()
{
	if(Input.GetButton("Fire2"))
	{
		weapon.transform.localPosition = Vector3.Lerp(weapon.transform.localPosition, aimPos, Time.deltaTime * 8);
		mainCam.fieldOfView = Mathf.Lerp(mainCam.fieldOfView, 45, Time.deltaTime * 10);
	}
	else
	{
		weapon.transform.localPosition = Vector3.Lerp(weapon.transform.localPosition, normalPos, Time.deltaTime * 8);
		mainCam.fieldOfView = Mathf.Lerp(mainCam.fieldOfView, 60, Time.deltaTime * 10);
	}
}

This is just a guess, but make sure that the Camera in your scene is tagged as your mainCamera. You can change the tag by selecting the camera and clicking the tag drop down menu in the inspector.

Ps. I can’t really give you much more of an answer without seeing the error and a more descriptive question.