How can I Get an Objects Rigidbody from another Scripto?

Alrighty so I got the 1st part of it going smoothly. This is how I find my GameObjects RigidBody.

	public Rigidbody2D CollidedOBJRB;

	public void OnTriggerStay2D (Collider2D coll) {

		if (coll.gameObject.tag == ("Player") && coll.gameObject.tag != HitBoxHere.tag
		    coll.gameObject.tag == ("CPU") && coll.gameObject.tag != HitBoxHere.tag) {
			CollidedOBJRB = coll.GetComponent<Rigidbody2D>();

So basically if I collide with a certain Object of that If Statement.

My GameObject(CollidedOBJ) will equal to the Collided GameObject.

That works fine. I tested it BUT!

Then when I try to put the HitBoxScript and it’s Object into my other Script I get an Issue.

HitBoxScript Force = HitBox.GetComponent<HitBoxScript>();
//HitBox is a GameObject in my Currently used Script.

This Works fine too, No errors or nothing. But!

When I do something that allows me to change the Velocity I get some sort of annoying error for this line of Code.

			Force.CollidedOBJRB.velocity = new Vector2(PushX,PushY);

NullReferenceException: Object reference not set to an instance of an object
CharacterCross.Combos () (at Assets/Characters/Cross/CharacterCross.cs:225)
CharacterCross.Update () (at Assets/Characters/Cross/CharacterCross.cs:841)

All in all, what I’m trying to do is, allow my HitBox to give force onto the CollidedOBJ Rigidbody by changing it’s velocity. But it seems, a little bug is getting in my way. What’s up with that?

Any Help would be appreciated, dudes.

It depends on where Force.CollidedOBJRB.velocity = new Vector2(PushX,PushY); is in that script.
Unless you enter the trigger, it’s going to be null. I don’t know if you’re updating it when it leaves the trigger, but if you are, then it’d be null then too.

Essentially, you want to check if it is null (meaning it isnt in the trigger zone) before using any value of the game object. So, do:

if (Force.ColliderOBJRB != null) Force.CollidedOBJRB.velocity = new Vector2(PushX,PushY);