Can't seem to get bool/SetActive Script to work

Hello. Recently I have been trying to make scripts with my own brain and not copy off other tutorials, But in the process I have been going through many problems. One of the problems I am having with right now is to get this bool/SetActive script to work. What I am trying to do is that when the character finds a certain chest and interacts with the chest it will set the givensword bool to true. After that I have a script seeing if I click Alpha1 what will happen is it will check if the givensword is true and if soo it will set the SetActive of the sword to true. What I found is that when I do not add the check to see if givensword is true then the script will work, But if I do add the givensword check it will say “Null reference not set to an instance of the object” I hope that I can figure out this problem fast so I can continue on with this game. Thank you for taking the time in helping me!

The Chest Script

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

public class Chest : ActionItem {
    public bool givensword = false;

    public override void Interact()
        Debug.Log("Interacting with Chest");
        givensword = true;

Sword SetActive Script

     public GameObject Sword;
    Chest swordHasBeenFound;

//Take out Sword
        if (Input.GetKey(KeyCode.Alpha1) && swordOut == false && swordHasBeenFound.givensword == true)
            swordOut = true;
        if(Input.GetKey(KeyCode.Alpha1) && swordOut == true && swordHasBeenFound.givensword == true)
            swordOut = false;

You never defined swordOut in the scripts you provided us.

swordHasBeenFound is of type Chest. Since it is a private variable you need to set it inside of your script, preferably in Awake() or Start(). It’s not set which is why you’re getting a null reference error when attempting to access it…