Trying to destroy a cube....

I am trying to destroy a object by pressing space but not sure what i am doing wrong.
I am complete newbie at this.

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

public class attack : MonoBehaviour
{
    public GameObject NPC;
 
   private void OnTriggerEnter(Collider other)
    {
        if (Input.GetKey(KeyCode.Space))
        {
            Destroy(NPC);
        }
    }
}

Put it in update instead of ontriggerenter

void Update()
{
    if (Input.GetKey(KeyCode.Space))
        {
            Destroy(NPC);
        }
}

hey it worked, thank you