need teleport script fixed slightly

so i found this script by blackstorm to teleport the player on mouse click in a 2D game but it uses the camera’s position the bad thing is my camera sits at -1 on the z position and everything else on the 0 z, if i dont do this the camera will not see the player or anything in the game for that matter how would i teleport to the mouse click but keep my players Z position?
help would be appreciated.

//Set up a variable to access the player from
private Transform player; 
 
void Awake()
{
//Find the player object and set it
player = GameObject.FindGameObjectWithTag("Player").transform;
}
 
void Update()
{
// Check if you click the left mouse button then change position
if (Input.GetMouseButtonDown(0))
player.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}

Use a temporary variable like so, insert instead of line 14

Vector3 targetPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
targetPosition.z = 0;
player.position = targetPosition;