Question by 
               FlyingCreator222 · Jan 25, 2019 at 04:26 PM · 
                c#errorunityeditor  
              
 
              My collectible/score script isn't working. Anyone have any idea why?
My collectible/score script isn't working. It should add 1 to score every time player collides with something with the tag "collectible". Right now it just gives this message when colliding with a collectible. The error is this: NullReferenceException: Object reference not set to an instance of an object score.OnTriggerEnter (UnityEngine.Collider col) (at Assets/Scripts/score.cs:27) Anyone have any idea why? Here is the code of my score script:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 public class score : MonoBehaviour {
     public float Score = 0;
     public float previous = 0;
     public Text sscore;
     public float emptyValue = 0;
     // Start is called before the first frame update
     void Start()
     {
 
     }
 
     // Update is called once per frame
     void FixedUpdate()
     {
 
     }
     void OnTriggerEnter(Collider col)
     {
         if (col.gameObject.tag == "collect")
         {
             Score = previous + 1;
             previous = Score;
             sscore.text = Score.ToString();
             Debug.Log(Score);
             Destroy(col.gameObject);
         }
     }
 }
If someone finds a fix, thank you! Oh, and this is a 3d project.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by xxmariofer · Jan 25, 2019 at 04:42 PM
click in the object that script is attached too, and make sure the sscore var is assigned, 90% sure thats the error.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                