I want to make a script whereas the player cannot move backwards or go backwards or go the opposite direction, basically they are stuck only moving in one direction but they can still move right and left to steer, does anyone know how to do this?
Only way I can think of is disabling movement then coding your own custom movement using UserInputService.
i disabled the s keybind for the player but it doesnt work on mobile, how do i make it work on mobile?
On top of disabling inputs, you may also want to clamp a player’s position.
Say for example:
- My player starts at a position of (0, 0, 0).
- He is only allowed to move in the +y direction.
You need to clamp the player’s Y position as such:
- Start at (0, 0, 0)
- Player moves to (0, 1, 0), server accepts this as the change is +y
- Player tries to move to (0, 0.9, 0), server refuses this and sets him back to (0, 1, 0) because the change is -y
Ideally you want the player to be facing exactly in a X, Y, Z condition so your server only has one axis to consider.
I think this will cause stuttering though, but this is a rudimentary idea to get you started.
Some other ideas:
- just put an invisible barrier that follows behind the player.
- use their humanoid’s MoveDirection to determine its movement. If it’s Y direction is negative (meaning they are moving backwards), zero their move speed.
I used humanoid.movedirection:Dot to fix this issue and it worked, so thanks for the advice
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.