Check bool from multiple instances of the same script

Hello, I am trying to check if a bool on a script is false if it leaves the collider.
The “dropzones” objects all have the tag “dropzone” and the script “DropZone1” is in the scene multiple times, attached once to each of the dropzone objects. In their Start Function, I have written satisfied as false.
My boundary script looks like this:

public class DestroyByBoundary : MonoBehaviour
{
    GameObject[] dropzones;
    DropZone1 dropzonescript;
    GameController gameController;

    private void Start()
    {
        gameController = FindObjectOfType<GameController>();
        dropzones = GameObject.FindGameObjectsWithTag("dropzone");
        foreach (GameObject zones in dropzones)
        {
            DropZone1 dropzonescript = zones.GetComponent<DropZone1>();
        }
    }
    void OnTriggerExit(Collider other)
    {
        
        if (other.gameObject.tag == "dropzone")
        {
            verifyifSatisfied(dropzonescript.satisfied);
        }
        
    }
    void verifyifSatisfied(bool satisfied)
    {
        
            if (dropzonescript.satisfied == false)
            {
                gameController.NoAnswer();
                gameController.DecideIfDisplay();
            }
        
    }
}

I would like to make it so if one of those “dropzones” leaves the collider, it calls that “verifyifsatisfied” function. However, whenever I test, the code has a nullreferenceexception. Is there a way to fix this?

Try something along the lines of this.

I still don’t know what the foreach is for, though.

public class DestroyByBoundary : MonoBehaviour
{
	GameObject[] dropzones;
	//DropZone1 dropzonescript;  // Ady: Delete this
	GameController gameController;

	private void Start()
	{
		gameController = FindObjectOfType<GameController>();
		dropzones = GameObject.FindGameObjectsWithTag("dropzone");
		foreach (GameObject zones in dropzones)
		{
			// Ady: I have no idea what you were trying to do here
			//DropZone1 dropzonescript = zones.GetComponent<DropZone1>();   // Ady disabled code
		}
	}

	void OnTriggerExit(Collider other)
	{
		if (other.gameObject.tag == "dropzone")
		{
			// Ady: Gets the DropZone1 script that's attached to the object that exited the trigger
			var dropzonescript = other.GetComponent<DropZone1>();  // Ady
			verifyifSatisfied(dropzonescript);  // Ady
		}
	}
	
	void verifyifSatisfied(DropZone1 dropzonescript)  // Ady: Replaced parameter with DropZone1 type
	{
		if (dropzonescript.satisfied == false)
		{
			gameController.NoAnswer();
			gameController.DecideIfDisplay();
		}
	}
}

From what I can understand, yourDestroyByBoundary script should look like this:

public class DestroyByBoundary : MonoBehaviour {
    GameController gameController;
    
    private void Start () {
        GameController = FindObjectOfType<GameController> ();
    }
    
    void OnTriggerExit (Collider other)  {
        if (other.gameObject.CompareTag ("dropzone")) {    //is better to use ".CompareTag ("YourTag")" then ".tag == "YourTag"
            if (other.getComponent<DropZone1> ()) {
                verifyifSatisfied (other.getComponent<DropZone1> ().satisfied);
            }
        }
    }
    
    void verifyifSatisfied (bool satisfied) {
        if (!satisfied) {    //"!satisfied" is the same as "satisfied == false"
            gameController.NoAnswer ();
            gameController.DecideIfDisplay ();
        }
    }
}

And to make it even more polished, you could even summarize it like this:

public class DestroyByBoundary : MonoBehaviour {
    GameController gameController;
    
    private void Start () {
        GameController = FindObjectOfType<GameController> ();
    }
    
    void OnTriggerExit (Collider other)  {
        if (other.gameObject.CompareTag ("dropzone")) {
            if (other.getComponent<DropZone1> () && other.getComponent<DropZone1> ().satisfied) { {
                gameController.NoAnswer ();
                gameController.DecideIfDisplay ();
            }
        }
    }
}

Let me know if this helps.