2D Platformer Reload Game On Collision With Sprite

Hello, I am trying to make a script that I can place within a 2D sprite that has a boxcollider2D within it in my 2D platformer. I have been trying to make it reload the level when the player touches the object. I have been trying this script but I can’t get it to work. What am I doing wrong?

public class Restart : MonoBehaviour
{
  
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Player")
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    }

}

You using OnTriggerEnter2D so at least one of your colliders (boxcollider2D or player Collider) must be trigger (isTrigger in inspector). And if any collider in your game moving at runtIme you must attach Rigidbody2D to this gameObject.