A problem with movement

Hi, thanks for any help you can offer me. I have a script called Control, it allows you to select the player gameObject (turning it blue) then hopefully move it. The issue with this is that I’m having problems with the movement. You select the area you wish to move to and it instead just moves diagonally to the same spot no matter where you click. Just for to clarify, player is a gameobject not a Transform.

EDIT: My variables:

public float speed = 3.0f; 

	public GameObject player;


	private Vector3 clickPos = Vector2.zero;

	//public bool rayFired = false;
	public bool selected = false;
	// Raybased Variables
	public RaycastHit hit = new RaycastHit ();

	public Ray leftRay; 

Then my MovePlayer()

IEnumerator MovePlayer ()
	      {
		if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition))) 
		{
			clickPos = hit.point;
		

		while (Vector3.Distance(clickPos, player.transform.position)>0.01f)
		{

			player.transform.position = Vector3.Lerp(player.transform.position,clickPos, Time.deltaTime * speed);
			yield return new WaitForEndOfFrame();
		}

		}
			
			}

I then call it in Update:

if (Input.GetMouseButtonDown (1)) 
		{
			StartCoroutine(MovePlayer());
			}

I want the player to move to the position of hit.point.

Your raycast is not actually capturing the information into your raycast hit variable. You need to use a different overload of Physics.Raycast

if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))