Enable/Disable Script

I have a 2 player racing game and i’m trying to make a script so both players can be ready and then start the race. I have a Game Controller Script and 2 Scripts for my 2 players. On my Game Controller script i’m trying to enable players scripts when they both are ready. This is my Game Controller script:

`public class GameCTRL : MonoBehaviour {

private Player_1CTRL p1script;
private Player_2CTRL p2script;

private bool player1Ready;
private bool player2Ready;

void Start (){
	
	p1script = GetComponent<Player_1CTRL> ();
	p2script = GetComponent<Player_2CTRL> ();

	p1script.enabled = false;
	p2script.enabled = false;
	
	player1Ready = false;
	player2Ready = false;
	
}

void Update(){

	if (Input.GetKeyDown (KeyCode.UpArrow)) {
		player1Ready = true;
	}

	if (Input.GetKeyDown (KeyCode.W)) {
		player2Ready = true;
	}

	if (player1Ready && player2Ready) {
		p1script.enabled = true;
		p2script.enabled = true;
	}
 }

}’

I don’t know why but when i run my game i get this error:

NullReferenceException: Object reference not set to an instance of an object
GameCTRL.Start () (at Assets/Scripts/GameCTRL.cs:28)

Thank you!

try saving your scene and project then restart unity.

I have a bug where every 30 minutes or so it will ask me to fix compiler errors even though there are none… probably this is another variation of that bug.

Also make sure all your brackets are properly set up, the most common error I make is putting in too many or too few brackets!

@eRlind

Try the following changes in GameCTRL

void Start ()
{
    p1script = GetComponent<Player_1CTRL> ();
    p2script = GetComponent<Player_2CTRL> ();

    if (p1script == null)
    {
        Debug.LogError("Start: p1script is null, no attached Player_1CTRL component");
    }
    if (p2script == null)
    {
        Debug.LogError("Start: p2script is null, no attached Player_2CTRL component");
    }
    p1script.enabled = false;
    p2script.enabled = false;

    player1Ready = false;
    player2Ready = false;
}

void Update()
{
    if ((p1script != null) && (p2script != null))
    {
        if (Input.GetKeyDown (KeyCode.UpArrow))
        {
            player1Ready = true;
        }
        if (Input.GetKeyDown (KeyCode.W))
        {
            player2Ready = true;
        }
    }
    if (player1Ready && player2Ready)
    {
        p1script.enabled = true;
        p2script.enabled = true;
    }
}