A case of the object reference (edited)

I’m beyond confused on how my script still has a error causing the common error message of object reference. Im wondering if theres anything anyone can spot that im overlooking. The error is on line 16 of the first script.

Script 1

public class ShootSlider : MonoBehaviour {
    public float value;
    public float shootTime;
    public GameObject UI;
    public Slider slider;
    private BoatMovement boatscript;
    

    void Start () {
        GameObject boat = GameObject.Find("Boat");
        BoatMovement boatscript = boat.GetComponent<BoatMovement>();
    }
	
	// Update is called once per frame
	void Update () {
        value = boatscript.GetComponent<BoatMovement>().timeStamp;
        slider.value = value;
	}
}

Script 2 (The one im trying to reference)

public class BoatMovement : MonoBehaviour {

    public GameObject boat;
    public Rigidbody rb;
    public Transform tr;
    public float speed = 500f;
    public float turnspeed = 0.001f;
    public GameObject cannonBall;
    public Transform firePoint;
    public Transform firePoint2;
    public Transform firePoint3;
    public Transform firePoint4;
    public float timeStamp = 5f;


    void Start () {
		
	}
	
	public void FixedUpdate () {
        
		if(Input.GetKey("w"))
        {
            rb.AddForce(tr.forward * speed * Time.deltaTime);
        }
        if (Input.GetKey("a"))
        {
            transform.Rotate(0,-1,0 * turnspeed * Time.deltaTime);
        }
        if (Input.GetKey("d"))
        {
            transform.Rotate( 0,1,0 * turnspeed * Time.deltaTime);
        }
        if(Input.GetMouseButtonDown(1) && timeStamp <= Time.time)
        {
            timeStamp = Time.time + 2;

            Shootright();
        }
        if (Input.GetMouseButtonDown(0) && timeStamp <= Time.time)
        {
            timeStamp = Time.time + 2;
            Shootleft();
        }

    }
    void Shootright()
    {
        Instantiate(cannonBall, firePoint.position, firePoint.rotation);
        Instantiate(cannonBall, firePoint2.position, firePoint2.rotation);
    }
    void Shootleft()
    {
        Instantiate(cannonBall, firePoint3.position, firePoint3.rotation);
        Instantiate(cannonBall, firePoint4.position, firePoint4.rotation);
    }
    
}

Hello there,

To keep it short, “boatScript” is already an instance of BoatMovement. So you don’t need to get that component from it in Update.

Replace that line with value = boatscript.timeStamp; and you’ll be fine.


Hope that helps!

~Cheers,

LegendBacon

First, your object with the script atached is boat?
Nesxt, when you reference you boatscript, the when you want a reference of it you dont need to get the comonent as you are doing on the update of first script because the script doesnt hace the reference on itself. just put
boatscript.timeStamp

WOW, after some face-palms and some thoughts of abandoning the project as a whole I scrapped the entire works and went for a more math related approach using time past and etc etc. Thank you guys for you help the script works just fine now!