How to stop an object from moving past a certain position

Hi, so I am trying to make a pong clone in Unity and I am having difficulties with a certain thing. I have set boundaries for the paddles by simply using other cubes to block them but I want to set the paddles y position to stop once it reaches the number 3.41 without using collisions even though I have them set for colliding with the ball. How could I achieve this?

It’s rather simple:

public void movement() {
    if(Input.GetKey(KeyCode.S)) {
        if(transform.position.y <= 3.41f) {
              // allowed to move
        } else {
            Vector3 newPosition = new Vector3(transform.position.x, 3.41f, transform.position.z);
            transform.position = newPosition;
        }
    }
} 

Explanation: When you hold “S” the code checks if the y position of the game object is lower or equal to 3.41. If it is, you can move. If it exceeds 3.41, the gameobject will be set back to this max position and for the player it looks like there is an invisible wall.

You can also replace the cubes with this method.