Object referance not set to an instance of an object?

I am using a raycast script but it says “Null Referance Exeption Object referance not set to an instance of an object”, and doesn’t print anything
How do i fix this

function Update () {

var foundHit : boolean = false;

var hit : RaycastHit;
if (Input.GetButton("Fire1")){

    if (Physics.Raycast(transform.positon, transform.forward))
        print("YES");
    else 
        print("NO");
}

}

You are not hitting anything. I don’t think raycasthit can be converted to boolean so you are passing null to an if statement where it expects bool. First cast your ray, check for input, check if hit.collider != null.