How to get rid of the null reference error?

Hello! I am currently making a 2D platformer game and I am dealing with an error that is probably happening on my UpdateBestTime() method and I really can’t find the solution for that need help.

Here is the error I am handling:

bestTimeText is null in UpdateBestTime!
UnityEngine.Debug:LogError (object)
GameManager:UpdateBestTime (int) (at Assets/Scripts/GameManager.cs:281)
GameManager:LoadBestTimeOnStartGame () (at Assets/Scripts/GameManager.cs:296)
GameManager:Awake () (at Assets/Scripts/GameManager.cs:51)

Here is the code for game manager:

using System.Collections;
using TMPro;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    // Variables initialization

    [SerializeField] TextMeshProUGUI timerText;
    [SerializeField] TextMeshProUGUI bestScoreText;
    [SerializeField] TextMeshProUGUI bestTimeText;

    private PlayerController playerController;
    private AudioManager audioManager;
    public UIManager uiManager;

    public GameObject pauseMenuScreen;
    public GameObject gameOverMenuScreen;
    public Transform startingPoint;
    public Animator animator;

    private float speed = 10f;
    public float time;

    public int bestScore;
    public int bestTime;

    public GameState currentState = GameState.Playing;


    private void Awake()
    {
        currentState = GameState.Playing;

        // Assign playerController first
        playerController = GameObject.Find("Player")?.GetComponent<PlayerController>();
        CheckPlayerControllerNullReference(); // Ensure playerController is not null before proceeding

        // Assign other components and perform null checks
        audioManager = GameObject.Find("AudioManager")?.GetComponent<AudioManager>();
        uiManager = GameObject.Find("UIManager")?.GetComponent<UIManager>();
        animator = GetComponent<Animator>();

        // Check other null references
        CheckPauseMenuScreenNullReference();
        CheckGameOverMenuScreenNullReference();
        CheckBestScoreTextNullReference();

        // Load best score and time
        LoadBestScoreOnStartGame();
        LoadBestTimeOnStartGame();

        // Update best score and time
        UpdateBestTime(bestTime);
        UpdateBestScore(bestScore);

        // Check for null bestTimeText
        if (bestTimeText == null)
        {
            Debug.LogError("bestTimeText is null in Awake!");
        }
    }

    private void Start()
    {

    }

    private void Update()
    {
        switch (currentState)
        {
            case GameState.Playing:
                uiManager.InputForPauseMenuScreen();
                Time.timeScale = 1f;
                break;

            case GameState.Paused:
                uiManager.InputForPauseMenuScreen();
                Time.timeScale = 0f;
                break;

            case GameState.GameOver:
                GameOver();
                break;
        }
        UpdateTimer();
    }

    public enum GameState
    {
        Playing,
        Paused,
        GameOver,
    }

    public void CheckPauseMenuScreenNullReference()
    {
        if (pauseMenuScreen != null)
        {
            pauseMenuScreen.SetActive(false);
        }

        else
        {
            Debug.Log("Pause menu screen not found!");
        }
    }

    public void CheckGameOverMenuScreenNullReference()
    {
        if (gameOverMenuScreen != null)
        {
            gameOverMenuScreen.SetActive(false);
        }

        else
        {
            Debug.Log("Game over menu screen not found!");
        }
    }

    public void CheckPlayerControllerNullReference()
    {
        if (playerController != null)
        {
            playerController.playerRb.AddForce(Vector2.up * playerController.startJumpForce, ForceMode2D.Impulse);
            StartCoroutine(PlayIntro());
            Debug.Log("The game started!");
        }

        else
        {
            Debug.Log("Player controller not found!");
        }
    }

    public void CheckBestScoreTextNullReference()
    {
        if (bestScoreText != null)
        {
            bestScoreText.text = "Best Score: " + bestScore;
        }

        else
        {
            Debug.Log("Best score text not found!");
        }
    }

    // We use an IEnumerator to make out starting point animation 
    IEnumerator PlayIntro()
    {
        Vector3 startPos = playerController.transform.position;
        Vector3 endPos = startingPoint.position;

        float journeyLength = Vector3.Distance(startPos, endPos);
        float startTime = Time.time;
        float distanceCovered = (Time.time - startTime) * speed;
        float fractionOfJourney = distanceCovered / journeyLength;

        while (fractionOfJourney < 1)
        {
            distanceCovered = (Time.time - startTime) * speed;
            fractionOfJourney = distanceCovered / journeyLength;

            if (playerController != null)
            {
                playerController.transform.position = Vector3.Lerp(startPos, endPos, fractionOfJourney);
            }

            else
            {
                Debug.Log("PlayerController not found!");
            }
            yield return null;
        }
    }

    public void GameOver()
    {
        gameOverMenuScreen.SetActive(true);
        audioManager.mainGameMusicAudioSource.Stop();
        currentState = GameState.GameOver;
        Debug.Log("Game is over: " + GameState.GameOver);
    }



    public void PauseGame()
    {
        if (currentState == GameState.Playing)
        {
            currentState = GameState.Paused;
            pauseMenuScreen.SetActive(true);
            audioManager.mainGameMusicAudioSource.Pause();
            audioManager.PressButtonSound();
            Time.timeScale = 0f;
            Debug.Log("Pause menu screen is enabled after delay!");
        }
    }

    public void ResumeGame()
    {
        if (currentState == GameState.Paused)
        {
            currentState = GameState.Playing;
            pauseMenuScreen.SetActive(false);
            audioManager.mainGameMusicAudioSource.UnPause();
            audioManager.PressButtonSound();
            Time.timeScale = 1f;
            Debug.Log("Pause menu screen is disabled after delay");
        }
    }

    public void UpdateTimer()
    {
        if (timerText != null)
        {
            time += Time.deltaTime;
            int minutes = Mathf.FloorToInt(time / 60);
            int seconds = Mathf.FloorToInt(time % 60);
            timerText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
            timerText.text = "Timer: " + timerText.text;
            Debug.Log("Timer updates: " + timerText.text);
        }
    }

    public void CheckSaveBestScore()
    {
        if (playerController.score > bestScore)
        {
            bestScore = playerController.score;
            PlayerPrefs.SetInt("BestScore", bestScore);
            PlayerPrefs.Save();
            Debug.Log("Best score is: " + bestScore);
            Debug.Log("Checked and saved best score!");
            UpdateBestScore(bestScore);
        }
        bestScoreText.text = bestScore.ToString();
    }

    public void CheckSaveBestTime()
    {
        if (time > bestTime)
        {
            bestTime = (int)time;
            PlayerPrefs.SetInt("BestTime", bestTime);
            PlayerPrefs.Save();
            Debug.Log("Best time is: " + bestTime);
            Debug.Log("Checked and saved best score!");
            UpdateBestTime(bestTime);
        }
        bestTimeText.text = bestTime.ToString();
    }

    public void UpdateBestScore(int bestScore)
    {
        if (bestScoreText != null)
        {
            bestScoreText.text = "Best Score: " + bestScore;
            Debug.Log("Best score updates: " + bestScore);
        }

        else
        {
            Debug.Log("Best score text not 

Contact me on discord to help me solve it if you can’t give me more helpful information here:

Discord: SteliosKrom#7459