How can I use the ontriggerenter2D and Input.Getkeydown at the same time

Whenever I do this it only creates the object if I am entering the collision whilst pressing the z key.

How can I solve this?

void OnTriggerEnter2D ( Collider2D collision )
{
    if( Input.GetKey(KeyCode.Z) )
    {
        cloneText = Instantiate( TextBox , Positioning.transform.position , Positioning.transform.rotation );
    }
}

void OnTriggerExit2D ( Collider2D collision )
{
    Destroy(cloneText);
}

What is your intent? Do you want to spawn a new TextBox clone every time that Z is pressed while in the trigger, or do you want the TextBox to only be seen while Z is held down?

In general, GetKeyDown and GetKeyUp are not reliable in the OnTrigger methods because OnTrigger methods get executed during the physics fixed updates while inputs are processed during the game logic Update loop. GetKeyDown is only true for the one frame in which the key was pressed.

You may consider using OnTriggerStay2D. This function will run on every frame as long as trigger interaction is ongoing:

private void OnTriggerStay2D(Collider2D collision)
{
    if(Input.GetKey(KeyCode.Z) && cloneText == null)
    {
        cloneText = Instantiate(TextBox, Positioning.transform.position, Positioning.transform.rotation);
        //Rather than creating and destroying this text box each time, you should consider
        //if simply enabling/disabling the GameObject will serve your purpose.
    }
}

By the way, to post code on these forums please use the </> button in the post editor to create a section of pre-formatted text like the section above.

I want to create one dialogue box whenever the collisions are triggered and pressed z and destroy it when not touching each other