I need to limit the rotation of my camera vertically

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FPSCam : MonoBehaviour
{
public Camera cam;
public float sensitivity;
public GameObject player;

private float roty;
private float rotx;

void Start()
{
    Cursor.visible = false;
    Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
    rotx = Input.GetAxis("Mouse X") * sensitivity;
    roty = Input.GetAxis("Mouse Y") * sensitivity;
    player.transform.Rotate(0, rotx, 0);
    cam.transform.Rotate(-roty, 0, 0);
}

}

Instead of calculating a delta rotation each frame, just keep track of your total rotation angles and set the overall rotation.

 private float roty;
 private float rotx;
 void Start()
 {
     Cursor.visible = false;
     Cursor.lockState = CursorLockMode.Locked;
     roty = 0;
     rotx = 0;
 }
 void Update()
 {
     rotx += Input.GetAxis("Mouse X") * sensitivity;
     roty += Input.GetAxis("Mouse Y") * sensitivity;

     roty = Mathf.Clamp(roty, -90, 90);

     player.transform.rotation = Quaternion.Euler(0, rotx, 0);
     cam.transform.rotation = Quaternion.Euler(-roty, 0, 0);
 }