unable to turn enntity on/off with raycast

I have a script that essentially is the raycast for a button, but i want a special object topop in and out that is defined by another script and it keeps giving me the error, i know what it means, it means that there is no value in the hit of the raycast so it can’t do the function, but i don’t know how to fix it

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FPbutton : MonoBehaviour {

public Camera playerCam;
public Transform playerCam1;
public GameObject hand;



// Use this for initialization
void Start () {
    hand.gameObject.SetActive(false);
}

// Update is called once per frame
void Update () {

    RaycastHit hit;
    Ray ray = playerCam.ScreenPointToRay(Input.mousePosition);
    if (Input.GetMouseButtonDown(0))
    {
        if (Physics.Raycast(ray.origin, ray.direction, out hit, 2))
        {
            Remotedoor remotedoor = hit.transform.GetComponent<Remotedoor>();
            if (remotedoor)
            {
                remotedoor.pressed = true;
                Debug.Log("press");
                
            }

        }
    }

    if (Physics.Raycast(ray.origin, ray.direction, out hit, Mathf.Infinity))
    {
        DetectScreen screen = hit.transform.GetComponent<DetectScreen>();

        if (Physics.Raycast(ray.origin, ray.direction, out hit, 2))
        {
            
            Remotedoor remotedoor = hit.transform.GetComponent<Remotedoor>();
            if (remotedoor)
            {

                if (screen)
                {
                    screen.active = true;
                }

            }

            if (Physics.Raycast(ray.origin, ray.direction, out hit, Mathf.Infinity))
            {
                DetectScreen screen1 = hit.transform.GetComponent<DetectScreen>();
                
                if (!screen)
                {
                    screen1.active = false;
                }
                else
                {
                    return;
                }
                
            }
            

            }
        
    }

    

    }

}

Like Vicarian said your nested raycast is highly uncessary looks like to me your code is not running because you have your screen reversed

what your saying here is if(screen == true) set it == true? that is the opposite of what you want to do here is some simplified code for ya and for the record tags

 void Update () {
     RaycastHit hit;
     Ray ray = playerCam.ScreenPointToRay(Input.mousePosition);
     if (Input.GetMouseButtonDown(0))
     {
         if (Physics.Raycast(ray.origin, ray.direction, out hit, 2))
         {
             if (hit.transform.GetComponent<Remotedoor>() != null)
             {
				 Remotedoor remotedoor = hit.transform.GetComponent<Remotedoor>();
                 remotedoor.pressed = true;
                 Debug.Log("press");
                 
             }
			 else if(hit.transform.GetComponent<DetectScreen>() != null)
			 {
				 DetectScreen screen = hit.transform.GetComponent<DetectScreen>();
				 screen.gameObject.SetActive(false); //wasnt sure what you were trying to do with the screen so I put this here
			 }
         }
     }