Keeping track of number of objects destroyed after the game is over

I try to get the amount of number of objects destroyed displayed when the game is over, but for some reason the value don`t change.

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

public class BlueWall : MonoBehaviour
{

    public static BlueWall Instance { get; private set; }

    [SerializeField] private GameObject blueWall;
    [SerializeField] private GameObject blueProjectile;


    private int blueWallDestroyAmount;

    private void Start()
    {
        Instance = this;
    }
    void OnTriggerEnter2D(Collider2D other)
    {

        if (other.CompareTag("BlueP"))
        {
            blueWallDestroyAmount++;
            Destroy(gameObject);
            Destroy(other.gameObject);
        }
        else
        {
          
            Destroy(other.gameObject);
        }

    }
    public int GetBlueWallDestroyAmount()
    {
        return blueWallDestroyAmount;
    }
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class IGameManager : MonoBehaviour
{
    public static IGameManager Instance { get; private set; }

    public event EventHandler OnStateChanged;
   private enum State
    {
        WaintingToStart,
        CountdownToStart,
        GamePlaying,
        GameOver,
    }

    private State state;
    private float waitingToStartTimer = 1f;
    private float countdownToStartTimer = 3f;

    private void Awake()
    {
        Instance = this;
        state = State.WaintingToStart;
    }

    private void Update()
    {
        switch (state)
        {
            case State.WaintingToStart:
                waitingToStartTimer -= Time.deltaTime;
                if(waitingToStartTimer < 0f)
                {
                    state = State.CountdownToStart;
                    OnStateChanged?.Invoke(this, EventArgs.Empty);
                }
                break;

            case State.CountdownToStart:
                countdownToStartTimer -= Time.deltaTime;
                if(countdownToStartTimer < 0f)
                {
                    state = State.GamePlaying;
                    OnStateChanged?.Invoke(this, EventArgs.Empty);
                }

                break;
            case State.GamePlaying:
                state = State.GamePlaying;
                if(Player.Instance.gameOver == true)
                {
                    state = State.GameOver;
                }

                OnStateChanged?.Invoke(this, EventArgs.Empty);
                break;
            case State.GameOver:
             
              
                    state = State.GameOver;
              
                OnStateChanged?.Invoke(this, EventArgs.Empty);
              
                break;
              
        }
        Debug.Log(state);
    }
    public bool IsGamePlaying()
    {
        return state == State.GamePlaying;
    }

    public bool IsCountdownToStartActive()
    {
        return state == State.CountdownToStart;
    }

    public float GetCountdownToStartTimer()
    {
        return  countdownToStartTimer;
    }

    public bool IsGameOver()
    {
        return state == State.GameOver;
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class GameOverUI : MonoBehaviour


{
    [SerializeField] private TextMeshProUGUI blueWallDestroyText;
    [SerializeField] private TextMeshProUGUI redWallDestroyText;
    [SerializeField] private TextMeshProUGUI greenWallDestroyText;
    [SerializeField] private TextMeshProUGUI yellowWallDestroyText;
    private void Start()
    {
        IGameManager.Instance.OnStateChanged += IGameManager_OnStateChanged;

       // Hide();
    }
  

    private void IGameManager_OnStateChanged(object sender, System.EventArgs e)
    {
        if (IGameManager.Instance.IsGameOver())
        {
            Show();

            blueWallDestroyText.text = BlueWall.Instance.GetBlueWallDestroyAmount().ToString();
            yellowWallDestroyText.text = YellowWall.Instance.GetYellowWallDestroyAmount().ToString();
        }
      //  else
      //  {
        //    Hide();
       // }
    }


    private void Show()
    {
        gameObject.SetActive(true);
    }
  //  private void Hide()
   // {
      //  gameObject.SetActive(false);
   // }
}

Every time you increment blueWallDestroyAmount you also destroy the wall itself (that holds the value) so the value is of course lost.

if (other.CompareTag("BlueP"))
{
            blueWallDestroyAmount++;
            Destroy(gameObject); //<-- you're destroying the wall gameObject here.
            Destroy(other.gameObject);
}

In fact accessing BlueWall.Instance.GetBlueWallDestroyAmount() after the value has been incremented will probably result in a NullRefException, since the Instance itself has been destroyed.

I know that Im destroying that game object there…but what should I do to have the number of destroyed items displayed when the game is over? I dont get a NullRefExeption but the number of destroyed objects doesnt change when I destroy them, but when the player is destroyed, the value change to 0.

Simply don’t store the number of destroyed items in the object you’re destroying (for obvious reasons: once the object doesn’t exist anymore neither does the count), store it elsewhere.

Btw, if you want to have more than one BlueWall in your game -I strongly suspect you do- you shouldn’t use a singleton pattern like you seem to be doing.

Singleton assumes there will only ever be a single instance of BlueWall in the game. Worse still, you singleton is bugged since it doesn’t enforce a single instance and BlueWall.Instance will return whichever BlueWall instance had its Start() method called last, so in practice you’re getting one instance completely at random.