I can't change a variable that is in another script.

I am trying to change a variable in ballControl.cs called playerScore inside the script enemyControl.cs:

public class enemyControl : MonoBehaviour {
public ballControl ball;

void Update()
{

    if(transform.position.x < 0)
    {
        ball.playerScore++; //playerScore is declared in ballControl.cs
    }

}

}

When I run the game, I get this error:
“NullReferenceException: Object reference not set to an instance of an object
enemyControl.Update () (at Assets/enemyControl.cs:16)”

What am I doing wrong?

First of all you need to find the reference of “ballControl” in your variable “ball” then you can access public members of that class. “ball” is null, firstly assign it.
Suppose you are having object “ABC” with script “ballControl” then add this method to your script.

void Start()
{
ball = GameObject.Find("ABC").GetComponent<ballControl>();
}