How to insert a clamp into this script ?

You’re always going to have a rough time reading back .eulerAngles, due to gimbal lock.

If you don’t understand that limitation, don’t read or write to .eulerAngles.

Instead, track your own rotations and clamp them yourself:

Notes on clamping camera rotation and NOT using .eulerAngles because of gimbal lock: