My game still in pause mode after pressed restart button in game over menu

Idk why it happened, I’m using the same code as the restart button from my pause menu because the restart button works just fine but not in the game-over menu. Does anyone know how to fix it? i cant find a way to make it work.

First when the game started, if I tried to restart the game by pressing the pause button, then the restart button, the game restarted and automatically moved just like the restart button should do, but if the game over menu invoke because my character dies, when I pressed the restart button, the game did restart but it’s freeze, I had to pause/unpause to continue play the game. The code for the restart button is the same for both the pause menu and game-over menu

using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class GameOverScreen : MonoBehaviour
{
    public Text pointsText;

    public void Setup(int score)
    {
        gameObject.SetActive(true);
        pointsText.text = score.ToString() + " ";
    }

    public void Restart()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        Time.timeScale = 1.0f;
        GameManager.score = 0;
        PlayerMovement.speed = 9;
        PlayerMovement1.speed = 9;
    }

    public void MainMenu()
    {
        SceneManager.LoadScene("Main Menu");
        GameManager.score = 0;
        PlayerMovement.speed = 9;
        PlayerMovement1.speed = 9;
    }
}


First Comment Down The Unnecessary Code Or Lines Like Remove The Start And Update Methods And Also Remove The Unnecessary Import Statements.

Are either the pause menu or game-over menu set to DontDestroyOnLoad? The first step of Restart() in your GameOverScreen script above will load a new scene. This may cause the GameOverScreen script to immediately unload and not run the rest of the function.

As an experiment, can you try moving the LoadScene to the last step of the Restart function?