transform.translate limits

Hi, im struggling to add limits to a robotic arm I have made.

it moves using different buttons/ joysticks on a xbox controller.
I want to limit its movement so it doesn’t clash with walls etc, so I have tried to add that the position has to be below 10 on the z axis.

if (Input.GetAxis("XboxLeftJoystickX") > 0 && Gantry.gameObject.transform.position.z < 10)
            Gantry.gameObject.transform.Translate(Vector3.forward * 0.5f * Time.deltaTime);

but this doesn’t work, can anyone help, I just need to know the best way of limiting these movements.

If anyone finds this thread looking for an answer its pretty simple I fixed it using transform.localposition e.g.
if (Input.GetAxis(“XboxLeftJoystickX”) > 0 && Gantry.gameObject.transform.localposition.z < 10)
Gantry.gameObject.transform.Translate(Vector3.forward * 0.5f * Time.deltaTime);