While this may have been marked as solved years ago, the marked solution only forces players using a keyboard to move backwards. This means it won’t force players using a phone or controller to move only backwards. Here’s a solution that would force players to move only backwards on all devices:
-- This will only work if this LocalScript is located here:
-- StarterPlayer > StarterCharacterScripts
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local PlayerScripts = Player:WaitForChild("PlayerScripts", 10)
local PlayerModule = PlayerScripts and PlayerScripts:WaitForChild("PlayerModule", 10)
local Controls = if PlayerModule then require(PlayerModule).controls else nil
game:GetService("RunService").PreAnimation:Connect(function(dt)
local currentMoveVector = Controls:GetMoveVector()
if currentMoveVector.Magnitude<=0 then
return
end
local modifiedMoveVector = Vector3.new(0, 0, math.max(0, currentMoveVector.Z))
local currentCameraOrientation = Vector3.new(Camera.CFrame:ToOrientation())
Player:Move(CFrame.fromOrientation(0, currentCameraOrientation.Y, currentCameraOrientation.Z):VectorToWorldSpace(modifiedMoveVector))
end)
Here’s a short video of what this solution looks like:
There’s also a free model version of the solution that uses attributes to limit the move direction. They can be used to do stuff like preventing the player from moving backwards: Simple Walk Restrictions - Roblox