This seemed easy enough, but I was surprised to find out how difficult and maybe not even possible it actually is to achieve. I know that you can use a body velocity and make it keep a velocity of 0 in a specific axis but I need it to be able to do that in an axis relative to the part. Here's a picture describing what I mean:
https://ibb.co/zVZVQyZ
Green means that it's allowed to move in this direction/axis
Red means that it's not allowed to move in this direction/axis
Check out look vectors.
Either constantly make it stay on the same number for the axis you want the same, using a while true do loop, or anchor the part and detect when it's touched and move it, this way, you can control where it goes and it never goes off the axis unless you tell it to
I hope this helps :3