Script component seems to be missing when spawning prefab?

I’m making a racing game, and trying to spawn the characters into the stage as the match starts.

The spawning object has an array named racers, which contains all the prefabs for the characters, and an array named spawners, which has all the locations where racers can spawn. There is also a game object called “GameController” which has all the data for what players should spawn.

public class SpawnRacers : MonoBehaviour

	public GameObject[] racers;
	public GameObject[] spawners;

	// Use this for initialization
	void Start ()
		Destroy (GameObject.FindGameObjectWithTag ("Player"));
		var r = GameObject.FindGameObjectWithTag ("GameController").GetComponent<SpawnDataScript> ();
		int start = (spawners.Length - r.GetPlayers ().Length) / 2;
		for (int i = 0; i < r.GetPlayers ().Length; i++) {
			GameObject g = (GameObject)Instantiate (racers [r.GetPlayers ()  *- 1], spawners [start + i].transform.position, Quaternion.identity);*
  •  	g.transform.Rotate(new Vector3(0,-100,0));*
  •  	if (i < r.GetHuman ()) {*
  •  		g.tag = "Player";*
  •  		GameObject.FindGameObjectWithTag ("MainCamera").transform.SetParent (g.transform);*
  •  	} else {*
  •  		g.tag = "Racer";*
  •  	}*
  •  	Debug.Log (g.tag);*
  •  	Debug.Log (;*
  •  	Debug.Log (g.GetComponent<MovementScript>().special);*
  •  	Debug.Log (GameObject.FindGameObjectWithTag ("Player").name);*
  •  	Debug.Log (GameObject.FindGameObjectWithTag ("Player").GetComponent<MovementScript>().special);*
  •  }*
  • }*
    The player is spawning in the right place, and most of the Debug.Log’s at the bottom print the correct result, but the player won’t move, and the error “Object reference not set to an instance of an object” shows up when running lines 27 and 29 (the ones that try to access MovementScript).
    From this it seems like MovementScript is missing on my player’s prefab, but it’s definitely there in the inspector… what’s going on?

You are getting that error probably because you destroy the player gameobject that holds the MovementScript.

Destroy (GameObject.FindGameObjectWithTag (“Player”));

Probably remove that line of code above and your problem may be solved.
Good luck.

I think I’ll be creating a new question soon, since clearly the bigger problem (and likely the cause of this one) is that prefabs won’t save.