Script finding a none-existing player clone

Hi!

I am making a simple player follow script and it is not working. When I checked what it is finding, it is finding “Player(Clone)”. There is no clone in the scene or in the prefabs. Why is it doing this?

My code.

using UnityEngine;
using System.Collections;

public class CameraFollow : MonoBehaviour {

	public GameObject target;

	void Start(){
		target = GameObject.FindGameObjectWithTag("Player");
	}

	void Update(){
		transform.position = new Vector3(target.transform.position.x, target.transform.position.y, -10);
	}
}

I dont know why there is Player(Clone), but you can solve your problem another way:

You can link your Player obj directly:

using UnityEngine;

public class CameraFollow : MonoBehaviour
{
	public Transform playerTrans;
	
	void Update()
	{
		transform.position = new Vector3(playerTrans.position.x, playerTrans.position.y, -10);
	}
}

Or you can simply make camera obj child of your Player obj.

I had this error too its what brought me here but i happened to think of a solution use the following

playerTrans = FindObjectOfType<PlayerControl> ().transform;

fill <“PlayerControl”>() with a unique script or component that is upon your character.