GameObject.FindGameObjectWithTag

Hi there,

so i have a game scene with scores. in that scene i created and empty gameobject that stores the score and still remains undestroyed in the Lose game scene. my motive is to display the player score on the lose screen. Something like ‘Your score is —’. The problem is that in the text component of the score element, i put a script. that script find gameobectwith tag (“score”) (which is the object which stores the store). when i play the game it finds the object. then when in the code, i try to acces the gameobject with that tag, it shows error. here is the relevant code.

public GameObject scoreholder ;

void Awake(){
	scoreholder = GameObject.FindGameObjectWithTag("Score1");
	}
	
	void Start () {
		
		myText = GetComponent<Text>();
		
		myText.text = "Your Score is " + scoreholder.score;
		}

plz help
thanks in Advance :smiley:
Note* i am a noob :stuck_out_tongue:

You should try:

 myText.text = "Your Score is " + scoreholder.GetComponent<YourScriptThatContainsThisVariable>().score;

THE ERROR IS UnityEngine.GameObject' does not contain a definition for score’ and no extension method score' of type UnityEngine.GameObject’ could be found (are you missing a using directive or an assembly reference?)