I have a piece of code that is supposed to generate a random tile map which it does for the server only. I can't figure out how to get it to sync to the players when they join it.How would I sync the prefabs that are instigated to the joining players? They load on one player (the server) but when another player joins they don't show up.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class GenerateLevel : NetworkBehaviour {
public int MapSize = 20;
public GameObject prefab;
public GameObject _LeftW;
public GameObject _RightW;
public GameObject _TopW;
public GameObject _Botw;
public GameObject SpawnLocRed;
public GameObject SpawnLocBlue;
public string map;
public override void OnStartServer()
{
    //base.OnStartServer();
    GetComponent<Renderer>().material.color = Color.blue;
}
void Start()
{
    if (!isServer)
    {
        return;
    }
    for (int c = MapSize / 2; c > -MapSize / 2; c--)
    {
        for (int r = -MapSize / 2; r < MapSize / 2; r++)
        {
            var t = Instantiate(prefab, new Vector3(r, 0, c), 
Quaternion.identity);
            NetworkServer.Spawn(t);
            Debug.Log("Col:" + c + " Row:" + r);
            if (Random.Range(0, 3) == 2)
            {
                t.GetComponent<RAISE>().Run();
                map += 1;
            }
            else
            {
                map += 0;
                if (c < 0 - MapSize / 4 && r > 0 + MapSize / 4)
                {
                   var red= Instantiate(SpawnLocRed, new Vector3(r, 2, c), 
Quaternion.identity);
                }
                if (c > 0 + MapSize / 4 && r < 0 - MapSize / 4)
                {
                   var blue= Instantiate(SpawnLocBlue, new Vector3(r, 2, c), 
Quaternion.identity);
                }
            }
            map += "r";
        }
        map += "c";
    }
    Debug.Log(map);
    if (MapSize % 2 == 0)
    {
        GameObject wt = Instantiate(_TopW, new Vector3(-.5f, 0, -MapSize / 2), Quaternion.identity);
        wt.transform.localScale = new Vector3(MapSize, 5, 1);
        GameObject wb = Instantiate(_Botw, new Vector3(-.5f, 0, MapSize / 2+1), Quaternion.identity);
        wb.transform.localScale = new Vector3(MapSize, 5, 1);
        GameObject wl = Instantiate(_LeftW, new Vector3(-MapSize / 2-1, 0, .5f), Quaternion.identity);
        wl.transform.localScale = new Vector3(1, 5, MapSize+2);
        GameObject wr = Instantiate(_RightW, new Vector3(MapSize / 2, 0, .5f), Quaternion.identity);
        wr.transform.localScale = new Vector3(1, 5, MapSize+2);
    }
    else
    {
        GameObject wt = Instantiate(_TopW, new Vector3(-.5f, 0, -MapSize / 2), Quaternion.identity);
        wt.transform.localScale = new Vector3(MapSize-1, 5, 1);
        GameObject wb = Instantiate(_Botw, new Vector3(-.5f, 0, MapSize / 2 + 1), Quaternion.identity);
        wb.transform.localScale = new Vector3(MapSize-1, 5, 1);
        GameObject wl = Instantiate(_LeftW, new Vector3(-MapSize / 2 - 1, 0, .5f), Quaternion.identity);
        wl.transform.localScale = new Vector3(1, 5, MapSize + 1);
        GameObject wr = Instantiate(_RightW, new Vector3(MapSize / 2, 0, .5f), Quaternion.identity);
        wr.transform.localScale = new Vector3(1, 5, MapSize + 1);
    }
    Debug.Log(MapSize % 2);
}
Here is the updated snippet code
public GameObject[] tiles = new GameObject[1000];
public string map;
public override void OnStartServer()
{
    //base.OnStartServer();
    GetComponent<Renderer>().material.color = Color.blue;
}
public void OnPlayerConnected(NetworkPlayer player)
{
    foreach(GameObject go in tiles)
    {
        NetworkServer.Spawn(go);
    }
}
void Start()
{
    if (!isServer)
    {
        return;
    }
    int temp = 0;
    for (int c = MapSize / 2; c > -MapSize / 2; c--)
    {
        for (int r = -MapSize / 2; r < MapSize / 2; r++)
        {
            var t = Instantiate(prefab, new Vector3(r, 0, c), Quaternion.identity);
            tiles[temp] = t;
            NetworkServer.Spawn(t);
         }
     }
}
After some fiddiling I got the tiles to spawn but they are not syncing ot the characters the henerate tile is running for each client seperatrly.


 
    
