Cant disable a script?

I have a script that disables the players movement, but it keeps telling me:

Object reference not set to an instance of an object

The script:

public var thePlayer : GameObject;

thePlayer.GetComponent("PlayerMovement").active = false;

I am not sure what the problem is?

Either thePlayer has not been set, or thePlayer does not have a PlayerMovement component attached to it.

Also, it’s better to use the Type version of GetComponent.

thePlayer.GetComponent(PlayerMovement).active = false;

Both are there

thePlayer is set.

PlayerMovement.js is there on the player

Try this out then and report back.

Debug.Log (thePlayer);
Debug.Log (thePlayer.GetComponent (PlayerMovement));

I found out why it wasn’t working, when spawning the player it made a new prefab, so I just made so it makes thePlayer = theCollider.gameObject;