Can't reload score

Hello. I’m trying to reload the score after I press “restart”. The score stops when I lose but when I press restart it won’t restart. Another issue is that when I’m in the main menu i can’t see the score but in background it keeps going up.

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

public class GameMaster : MonoBehaviour
{
public GameObject restartPanel;
public Text score;
private bool asLost;

private void Update()
{
if (asLost == false)
{
score.text = Time.time.ToString(“F0”);
}

}

public void GameOver()
{
asLost = true;
Invoke(“Delay”, 0.5f);
}
void Delay()
{
restartPanel.SetActive(true);
}
public void GoToGameScene()
{
SceneManager.LoadScene(“Game”);
}
public void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);

}
public void GoToMainMenu()
{
SceneManager.LoadScene(“MainMenu”);
}

Hi and welcome,
please use code tags. It’s the first sticky in this subforum.

I dont know what you mean by the score stops or starts. I believe you mean that it just goes up (unless you just lost)? That’s the case because you simply set it to Time.time, which counts the time since the start of the game. So if you play 10 seconds, go to the main menu, then go to your play scene again, then Time.time still returns some value above 10, which is likely not what you want. Instead you should save the time when you restart, which you can then subtract from the current time to get your new score.

You also dont have a score variable, but are only setting a text, which is bad practice.