SetActive not working

if have a script that is supposed to opens (sets active) an image and sets a bool to true when I click I and does the opposite when I click it again but It doesn’t work, it doesn’t change the bool or set SetActive to true I don’t know what’s wrong with it.

heres my script

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

public class Crafting : MonoBehaviour {

	public bool isOpen;

	public void Start(){
		gameObject.SetActive (false);
		isOpen = false;
	}

	void Update () {
		if (Input.GetKeyDown (KeyCode.I) && !isOpen) {
			gameObject.SetActive (true);
			isOpen = true;
		}
			
		if (Input.GetKeyDown (KeyCode.I) && isOpen) {
			gameObject.SetActive (false);
			isOpen = false;
		}
	}
}

That’s because in every frame in which I is pressed down, you’re activating the object (first block of code) and then immediately deactivating it again (second block of code). You only want to execute one or the other, so use else.

     if (Input.GetKeyDown (KeyCode.I) && !isOpen) {
         gameObject.SetActive (true);
         isOpen = true;
     }
         
     else if (Input.GetKeyDown (KeyCode.I) && isOpen) {
         gameObject.SetActive (false);
         isOpen = false;
     }

Once your GameObject is inactive, it will no longer run scripts.
You will need a different gameobject’s script to set the state of this gameobject.