Trying to get resource to respawn

Looking to get a basic resource gathering system working and having some trouble respawning my resource. Right now I am just working with 2 objects, a Tree (the resource) and the Roots (where all the respawn code is)

Everything works fine until my Roots try to spawn a new Tree. It keeps giving me the error: object od type GameObject has been destroyed but you are still trying to access it. You should either check to see if its null or not destroy it.

Here is my code:

public float respawnTime;
public bool respawnCooldown = false;
public GameObject basicTree;

void Update ()
{
   if (respawnCooldown == true)
   {
      if (respawnTime > 0)
      {
         respawnTime -= Time.deltaTime;
      }
      else
      {
         Respawn ();
      }
   }

   public void Respawn ()
   {
      var tree = (GameObject)Instantiate(basicTree, transform.position, Quaternion.identity);
      NetworkServer.Spawn (tree);
      respawnCooldown = false;
      respawnTime = 5;
   }
}

I’m writing this to be a multiplayer game, hence the extra Spawn line below the instantiate. Both the Tree and the Roots are prefabs, with the Tree being a child of Roots.

Any help at all would be great!

So the error is on line 21? If so I’d venture a guess that your GameObject “basicTree” is not a prefab, but instead a GameObject that was already a part of the scene and then later destroyed. Make sure that basicTree is a reference to a prefab in your Assets folder.

I assume basic tree is a prefab? It sounds like the error might actually be in your code that is chopping down the tree. We’d need to see that code. My guess is your destroying prefabs instead of instantiated objects.