prefab navagent doesnt work,prefab navmesh doesnt work

so basically I made this zombie and added a nevmesh agent to it. For the scripting all I did was ai.setdestination(player). It worked perfectly but when I made him into a prefab and dropped a second one all of the zombies in the map stopped working. Same thing happened when I duplicated him.Is there anything i’m missing?.,So basically I made a zombie that runs fully out of a names it worked perfectly but then I made it into a prefab and then every zombie in the scene stopped working. I’ve been trying to figure this out for a month but I can never know why its doing this.

Chances are the prefab is losing the player in the inspector… Assign the Player tag to your player like this: Screen capture - 37d2ebfef2d12dbbe3239517bc823fb8 - Gyazo

If you tag the player as a player then use something like:

Code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;


public class Fix : MonoBehaviour
{
    public NavMeshAgent agent;
    private GameObject player;


	// Use this for initialization
	void Start ()
    {
        player = GameObject.FindGameObjectWithTag("Player");
	}
	
	// Update is called once per frame
	void Update ()
    {
        agent.destination = player.gameObject.transform.position;
	}
}

Your enemy should follow the player if there is a valid path to him.