How to restrict where a mc can be on the stage?

How do I restrict a mc to a certain area of the stage? I am going to have some buildings on the top of my stage and I don’t want my character to be able to walk past the street level. So basically I don’t want him to be able to go off the stage or up some to be determined height.

I am VERY new to this so if you could write it in very clear code, that would be very much appreciated.

Thanks