I want my camera to follow the player only on the x axis

I want my camera to follow the player only on the x axis

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using static UnityEngine.GraphicsBuffer;

public class CameraController : MonoBehaviour
{
    public Transform player;
    private Vector3 offset = new Vector3(0, 8.74f, -15.79f);
    public Camera cam1;
    public Camera cam2;
    public Transform camTarget;

    void Start()
    {
        cam1.enabled = true;
        cam2.enabled = false;
        camTarget.position = player.transform.position;
    }

    void LateUpdate()
    {
        //offset the camera behind the player by adding to the player's position.
        cam1.transform.position = player.transform.position + offset;

        camTarget.rotation = Quaternion.LookRotation(player.forward, Vector3.up);
        cam1.transform.rotation = camTarget.transform.rotation;
        cam2.transform.rotation = camTarget.transform.rotation;
    }

    private void Update()
    {
        // change the camera view between first person and third person
        if(Input.GetButtonDown("CameraView")) 
        {
            cam1.enabled = !cam1.enabled;
            cam2.enabled = !cam2.enabled;
        }
    }

}

I’m beginner but
Have you tried

cam1.transform.position = new Vector3( player.transform.position.x, 8.74f, -15.79f);