How could I restrict the player from moving with W and S?

I’m trying to make it so the player can only move left and right. The problem is, I’m not sure where to start.

local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")

local function disableMovement(player, action)
	return Enum.ContextActionResult.Sink
end

ContextActionService:BindAction("DisableForwardMovement", disableMovement, false, Enum.PlayerActions.CharacterForward)
ContextActionService:BindAction("DisableBackwardMovement", disableMovement, false, Enum.PlayerActions.CharacterBackward)

Players.PlayerAdded:Connect(function(player)
	ContextActionService:BindAction("DisableForwardMovement", disableMovement, false, Enum.PlayerActions.CharacterForward, player)
	ContextActionService:BindAction("DisableBackwardMovement", disableMovement, false, Enum.PlayerActions.CharacterBackward, player)
end)

I think you meant restrict a player from moving with W and S, if I’m right?

This disallows W and S movements.

1 Like

Thank you! Yes, I did mean W and S.

1 Like

This works perfectly fine on PC, but my friend showed me that controller breaks it, and phone probably breaks it too. Is there any way to fix this besides completely disabling controller and phone?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.