My scripts doesn't work. Please help.,My random scene load doesn't work.

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

public class RestOnColl : MonoBehaviour
{

[SerializeField]
string strtag;

int rounds = 0;

private void OnCollisionEnter(Collision collision) {
    if (collision.collider.tag == strtag)
    {

        rounds = rounds + 1;

        if (rounds < 3) {
            
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);

        }
        if (rounds == 3) {

            int index = Random.Range(0, 3);
            SceneManager.LoadScene(index);

        }
    }
}

},

You are reloading the scene everytime rounds is less then 3. Then the variable resets back to 0, because you reload the scene.

The easiest solution would be to make the rounds variable static, so it doesn’t reset on scene load. Static basically makes the variable independent of the GameObject (in this case).

[SerializeField]
string strtag;
static int rounds = 0;