How do I fix NullReferenceException: Object reference not set to an instance of an object?

I’m currently in the middle of trying to write out a Game Manager, but this particular problem I’ve been trying to solve for hours, trying everything I could think of, and nothing I try is fixing it.

This is the problematic code:

   if (GameObject.Find("WinCollectable").GetComponent<DoughnutCollect> ().DoughnutIsCollected)
        {
            DoughnutWasCollected = true;
        }

For frame of reference, I’m trying to check (under the Update function) if a public bool on different script attached to a different game object is true, which becomes true when the player enters a capsule collider marked as a trigger, and assign that to a bool on the current script. This bool gets checked at a later point in the code for changing GameStates.

Any help would be appreciated, I need to get quite a few things done in a short amount of time and can’t spend too much time on this particular problem.

you may have to check for null

 GameObject collectableGO = GameObject.Find("WinCollectable");
if (collectableGO != null)
{
   DoughnutCollect dc =  collectableGO .GetComponent<DoughnutCollect> ();
   if (dc !=null && dc.DoughnutWasCollected)
{
   DoughnutWasCollected = true;
}
}