What's wrong with my code ?

Hello
i created two java scripts and i wanted to get a variable from the second script which is S2 and modify it in S1
S1 :

#pragma strict
var s2:S2;
function Start () {
s2 = GetComponent.<S2>();
}

function Update () {
s2.rb.useGravity = false;
}
 S2:
 
#pragma strict
var rb:Rigidbody;
function Start () {
  rb = GetComponent.<Rigidbody>();
  rb.useGravity = true;
}

function Update () {

}

Error :
NullReferenceException: Object reference not set to an instance of an object
S1.Update () (at Assets/S1.js:8)

The Update Function and Start functions require you to inherit from MonoBehavior, which I am not sure you are doing.

Have you assigned the game object which holds the S2 script to the slot of the S1 script in the inspector?

If so, it appears that the execution order of the scripts is just not working as it needs to be for your setup.
I.e. the S1 script is executed first, it tries to get the rb reference from the S2 instance but S2 hasn’t been able to initialize it yet. But, don’t mess around with the execution order now.

In order to fix this, you can do the following (which i strongly recommend for serious projects):

everything that does not rely on variables of other scripts should be done in Awake(), so grab the reference to the rigidbody in your S2 script in Awake. Afterwards, when Start is called, the variable should hold a ready-to-use reference. In Start you can grab the references to all the other stuff.

Get it using GetComponent and then change the variable inside
like
private ScriptName scriptOjb;
public GameObject object;
scriptObj = object.GetComponent();
scriptObj.Variable u want to change this should works