Unity crashes after I destroy a gameobject

So I wrote what I thought would be a simple script for destroying an object after doing something specific, but it crashes my game?

public class DestroyThis : MonoBehaviour
{
    public bool hasTalked;

    void Start()
    {
        hasTalked = false;
    }

    private void OnTriggerEnter2D(Collider2D player)
    {
        while (hasTalked == true)
        {
            if (player.gameObject.tag == "Player")
            {
                DestroyGameObject();
            }
        }
    }

    void DestroyGameObject()
    {
        Destroy(gameObject);
    }    
}

hasTalked becomes true once you talk to an npc, but once it does and the player triggers the object, the game literally freezes and there’s no way to escape other than ending unity through Task Manager. What is the problem??

while (hasTalked == true)
This line creates an infinite loop as hasTalked never changes inside of it, so the exit condition never happens.

You probably want:

if (hasTalked == true)

instead