Network Instantiate Pickup Problem

In my scene i’ve got an object, I spawn it using Network.Instantiate, at defined spanwpoints. I can get it to spawn just fine, but when there is more than 1 player, the object gets instantiated for every player. So if i have 2 players playing there will be 2 of these pickups in the exact same place.

What i have being done is that when a player collides with these pickups it increases their points. However, since there is multiple objects in the same place it duplicates their points again.

Is there a way to work around this? I seem to have hit a dead end.
Here is a chunk of the code doing this:

var dataPrefab : GameObject;
var dataSpawned : boolean = true;
var dataSpawnpoints : GameObject[];
var dataSpawnPoint : GameObject;
var lastSpawnPoint : GameObject;
 if (dataSpawned == false)
    	{	
    	   dataSpawnpoints = GameObject.FindGameObjectsWithTag ("dataSpawnpoint");
           dataSpawnPoint = dataSpawnpoints[Random.Range(r, dataSpawnpoints.length)];
    	   if (lastSpawnPoint != dataSpawnPoint)
           {			
    	      lastSpawnPoint = dataSpawnPoint;
    	      dataSpawned = true;
    	      var newData = Instantiate(dataPrefab, dataSpawnPoint.transform.position, dataSpawnPoint.transform.rotation);	
    	   }
    	   else dataSpawnPoint  = dataSpawnpoints[Random.Range(r,dataSpawnpoints.length)];

Try adding the above script to an empty object in the scene. The reason I’d try that is because this game object, unlike your player object, will never have to be duplicated and so there will never be two instances of the same script.

P.s: If you need to pass a variable such as a boolean between two scripts then you can just set the variable as static like so:

static var NewVar : boolean;

and retrieve its value by using the scripts name (the name of the script where the variable is declared etc) and then adding the variable name to the end like so:

if…
OtherScriptName.NewVar == true
then…

This can be useful if you later need to check the variables that are now in the empty object, hope this helps :slight_smile: