Getting Cursor position problem

Hi guys, i want to instantiate a tower at my cursor’s location when i click the tower’s button in the menu. My problem is that when i do a debug.log on my cursor’s position, it looks like 400,0,40 ( arround i dont remember the exact number). My point is , the tower does get instantiated but at a very far position… How can i solve this to get the “real” cursor position ? Thanks again guys !

So here’s my code to do that

void Update () 
{
	mousePos.x = Input.mousePosition.x;
	mousePos.y = floorYpos;
	mousePos.z = Input.mousePosition.z;
	
	ray = Camera.main.ScreenPointToRay(Input.mousePosition);
	
	if(Physics.Raycast(ray,out hit, Mathf.Infinity))
	{
		if (hit.transform.tag == "Guardian")
		{
			if(Input.GetMouseButtonDown(0))
			{
				checkIfClicked = true; // pops the menu over my "guardian"
			}
		}
	}
	
	if (summoninMonkey == true)
	{
		Instantiate(monkey,mousePos,transform.rotation);
		Debug.Log("its working");
		summoninMonkey = false;
	}
}

void OnGUI ()
{

	if(checkIfClicked == true)
	{
		
		GUILayout.BeginArea(new Rect(350,25,120,120));
		
		if (GUILayout.Button("Summon Monkey", GUILayout.Width(120), GUILayout.Height(30)))
		{
			summoninMonkey = true;
			Debug.Log("going to change cursor for tower");
		}
		
		if (GUILayout.Button("Close Menu"))
		{
			Debug.Log("Closing menu");
			checkIfClicked = false;
		}
		GUILayout.EndArea();

	}	
}

I am realllly new to Unity, but I was trying to deal with this same problem today.
Maybe I can help a bit.
You want to instatiate at the point where that ray you cast collided with your object, not at the mouse position.

So you do that Raycast in the if statement. You are going to want to use the value of hit

Physics.Raycast(ray,out hit, Mathf.Infinity)

You can now set a Vector3 to the location where the hit occurred:

Vector3 newVector3 = ray.GetPoint (hit) ;

Then use that value of newVector3 in your instantiate:

Instantiate(monkey, newVector3 ,transform.rotation);

I am not sure if there are other problems you are having, but that might get you closer.
Also I found this debug feature pretty helpful to visualize the ray:

Debug.DrawRay (ray.origin, ray.direction * 100, Color.yellow);