Quiz Game score doesn't add

My Game: True or False Quiz with randomized questions

My Goal: Score would add whenever the player hit the correct answer

My Problem: If I hit the correct answer, the score would be 1 but turns immediately to 0.
HERE IS MY CODE:

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


public class GameScript : MonoBehaviour {
	public Question[] questions;
	private static List<Question> uquestions;
	private Question cquestion;
	public int currentscore = 0;

	[SerializeField]
	private Text scoretxt;

	[SerializeField]
	private Text facttxt;

	[SerializeField]
	private Text truetxt;

	[SerializeField]
	private Text falsetxt;

	[SerializeField]
	private float delay = 1f;

	[SerializeField]
	private Animator animator;

	void Start()
	{
		if (uquestions == null || uquestions.Count == 0) 
		{
			uquestions = questions.ToList<Question>();
		}

		SetCurrentQuestion();
	}


	void SetCurrentQuestion()
	{
		
		int rquestion = Random.Range (0, uquestions.Count);
		cquestion = uquestions [rquestion];

		scoretxt.text = currentscore.ToString();
		facttxt.text = cquestion.fact;
		uquestions.RemoveAt (rquestion);

		if (cquestion.correct) {
			truetxt.text = "CORRECT";
			falsetxt.text = "WRONG.";

		} 
		else 
		{
			truetxt.text = "WRONG";
			falsetxt.text = "CORRECT";
		}

		//scoretxt.text = currentscore.ToString();
	}

	IEnumerator TransToQuestion()
	{
		uquestions.Remove(cquestion);

		yield return new WaitForSeconds (delay);

		SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex);
	}

	public void UserSelectTrue()
	{


		animator.SetTrigger ("True");
		if (cquestion.correct) 
		{
			currentscore++;
			Debug.Log ("Correct.");
		} 
		else 
		{
			Debug.Log ("Wrong.");
		}

		StartCoroutine(TransToQuestion());
	}



	public void UserSelectFalse()
	{
		animator.SetTrigger ("False");
		if (!cquestion.correct) 
		{
			currentscore++;
			Debug.Log ("Correct.");
		} 
		else 
		{
			Debug.Log ("Wrong.");
		}

		StartCoroutine(TransToQuestion());
	}



}

Please help me guysss!!

The short answer is you’re reloading the level for each question, therefore destroying and recreating your state every time. either don’t reload, or make the variable static ,or have a gameobject with DontDestroyOnLoad holding on to the score.

Hey _Neyy,
first of all. You really should make it a habit to use camelCase when you define variables (like you did with your method names :slight_smile: )

Now to your problem:
As hexagonius has pointed out, you are using the following line in your SetCurrentQuestion() to set your scoretext:

scoretxt.text = currentscore.ToString();

The problem is now, that you reload the whole scene as soon as the user has made a decision with calling

SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex);

In doing so, you are resetting the currentScore value back to 0 and again calling SetCurrentQuestion() which sets you text object to 0 as well.
You should try to stay in your current scene and update the scoreText.text component instead.
I think one possible fix would be to rewrite you coroutine like this:

IEnumerator TransToQuestion()
     {
         scoretxt.text = currentscore.ToString();
         uquestions.Remove(cquestion);
 
         yield return new WaitForSeconds (delay);
     }

Of course it would be better to update the text before you call the coroutine (my opinion :slight_smile: )
But in any case you should drop the idea of reloading the whole scene.

Hope i could help you.