Game over text not showning

So I am trying to make a game like fruit ninja, in which you basically click on a prefab using mouse and it destroys it, updating your score by 5. If you click on the bad prefab, you loose 5 points. If a good prefab falls on the sensor, an OnTriggerEnter method destroys the object and should run the gameOver Function, which should show a text Game Over. But the If statement that that triggers this is not working.

The target Mover script:

using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class targetMover : MonoBehaviour
{
    private gameManager gameManagerScript;
    private Rigidbody targetRb;
    int minForce = 16;
    int maxForce = 18;
    int minTorque = -10;
    int maxTorque = 10;
    int minPosX = -4;
    int maxPosX = 4;
    int posY = -6;
    public int pointValue;
    public ParticleSystem explosionParticle;
    public bool hasCollided = false;
   
    // Start is called before the first frame update
    void Start()
    {
        targetRb = GetComponent<Rigidbody>();
        //Adding Force, torque and assigning position to GameObject
        targetRb.AddForce(randomForce(), ForceMode.Impulse);
        targetRb.AddTorque(randomTorque(), randomTorque(), randomTorque(), ForceMode.Impulse);
        transform.position = randomPos();
        gameManagerScript = GameObject.Find("gameManager").GetComponent<gameManager>();
       
       
    }

    // Update is called once per frame
    void Update()
    {
       
    }

    private void OnMouseDown()
    {
        gameManagerScript.updateScore(pointValue);
        Instantiate(explosionParticle, transform.position, explosionParticle.transform.rotation);
        Destroy(gameObject);
    }

    private Vector3 randomForce()  //Generates a Random force and returns the random Vector
    {
        return Vector3.up*Random.Range(minForce, maxForce);
    }

    private float randomTorque()  //Generates a Random Torque and returns the random float
    {
        return Random.Range(minTorque, maxTorque);
    }

    private Vector3 randomPos()  //Generates a Random Force and returns the random Vector
    {
        return new Vector3(Random.Range(minPosX, maxPosX), posY);
    }

    private void OnTriggerEnter(Collider other)
    {


        Destroy(gameObject);

        if (other.gameObject.CompareTag("Target"))
        {
            gameManagerScript.gameOverMethod();
            Debug.Log("Object Fell");
        }




    }
}

The game Management script:

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

public class gameManager : MonoBehaviour
{
   
    public TextMeshProUGUI scoreText;
    public List<GameObject> targets;
    public int playerScore;
    public TextMeshProUGUI gameOver;
   
    // Start is called before the first frame update
    void Start()
    {
       
        playerScore = 0;
        StartCoroutine(spawnTargets());
        updateScore(0);
       

    }

    // Update is called once per frame
    void Update()
    {
       
    }
   
   

    IEnumerator spawnTargets()
    {
       
        while (true)
        {
            yield return new WaitForSeconds(1);
            int index = Random.Range(0, targets.Count);
            Instantiate(targets[index]);
           
        }
       
    }

    public void updateScore(int scoreToAdd)
    {
        playerScore += scoreToAdd;
        scoreText.text = "Score:" + playerScore;
    }

    public void gameOverMethod()
    {
        gameOver.gameObject.SetActive(true);
    }
}

Please help with this problem. I am new to unity

First, find out if your OnTriggerEnter is actually being called. Put a Debug.Log statement just inside and see what happens when something hits the trigger collider.

My onTriggerMethod is indeed being called, because the game objects get destroyed once they hit the sensor. I had put a Debug.Log Statement inside the if statement, but that didn’t get logged in the console. That is not being called

In this case it simply means that your other game object does not have the required tag (or it’s misspelt). Instead of using Tags, just create MonoBehaviours acting like tags and add them to the object, this way you avoid using hard coded strings (aka magic strings), and you can add code inside (for example it’s better to have the destroy code inside this script, to separate concerns):

public class Fruit : MonoBehaviour
{
    // Set to true in the Inspector if this Fruit is a target (triggers a game over)
    public bool isTarget;

    public void DestroyGameObject()
    {
        // maybe add some effects: sounds, particles...
        Destroy(gameObject);
    }
}

Then your trigger code would become:

if (other.gameObject.TryGetComponent<Fruit>(out var fruit))
{
    Debug.Log($"Fruit {fruit} hit the trigger area");
    fruit.DestroyGameObject();

    if (fruit.isTarget)
    {
        Debug.Log($"Game over! the fruit {fruit} was a target", fruit);
        gameManagerScript.gameOverMethod();
    }
}
else
{
    Debug.Log($"The object {other.gameObject} that hit the trigger area does not have a Fruit component attached");
}