Getting error while trying to show text

Hey my UI text is not displaying the value of diamonds i collected
here is code for it

void SetCountText()
{
score.text = diamondCount.ToString();
}

if (col.gameObject.tag == “diamond”)
{
Destroy(col.gameObject);
diamondCount = 1 + diamondCount;
SetCountText();

}

when i collect a diamond i got this error object reference not set to an instance or object, which is bs because i created a public Text score and in inspector i connected Text to it

ok, seriously, code tags.

are those two snippets in the same script? when you double click on the error in the output panel what line of code does it take you to?

http://pastebin.com/Ly5H1ctY here is my script <===== , its all in player script

have you found out whats wrong with my code??

in start

  score = GetComponent<Text>();

“set score to the text component on this gameobject”, most likely there isn’t a text component on the gameobject this script is attached to, therefore score is set to null

you don’t want this line if you are manually setting what “score” refers to in the inspector.

works perfectly fine now thanks :slight_smile: