If Else Statement does both

So I am trying to make a block that’s basically a dice roll for a shortcut but half of the time it does both sides of the if statements.

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

public class RNG : MonoBehaviour
{
    public GameObject edge;
    public int rngval;

    void OnTriggerEnter2D(Collider2D col)
    {
        rngval = Random.Range(0,2);
        if(col.tag == "Player")
        {
            if(rngval==0){
                Destroy(gameObject);
                Destroy(edge.gameObject);
            } else {
                col.transform.position = CheckPoint.GetActiveCheckPointPosition();
                Destroy(gameObject);
            }
        }
    }
}

Are you sure that you only get a single collision? Maybe this script is attached to more than one object? Keep in mind that destroying the gameobject only has effect at the end of the current frame. An if-else statement can never execute both bodies. This is only possible when you run the code two times or more often.

Please learn how to debug such observations. Just place some Debug.Logs in your code to see how often it actually runs. It’s probably a good idea to print out the rngval you rolled as well. Note that you can pass a gameobject reference as second parameter to Debug.Log. This gameobject is a “context” object. When you click on the log message in the console, Unity will highlight / ping that context object. This makes it easier to identify which object has actually created this message.