I tried to make a shift lock but it does not work correctly and sometimes… spins the player. does anyone have their own shift lock for controller script?
local ContextActionService = game:GetService("ContextActionService")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local shiftLocked = false
local function updateCharacterRotation()
local character = player.Character
if not character then return end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
humanoid.AutoRotate = not shiftLocked
end
local function toggleShiftLock(actionName, inputState)
if inputState ~= Enum.UserInputState.Begin then return end
shiftLocked = not shiftLocked
updateCharacterRotation()
end
ContextActionService:BindAction(
"ConsoleShiftLock",
toggleShiftLock,
false,
Enum.KeyCode.ButtonX
)
player.CharacterAdded:Connect(updateCharacterRotation)```
Here you go, should work: Place in starter player scripts
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local camera = workspace.CurrentCamera
-- Configuration
local TOGGLE_BUTTON = Enum.KeyCode.ButtonL3 -- Click Left Stick
local SENSITIVITY = 0.5
local OFFSET = Vector3.new(2, 2, 0) -- Adjust for shoulder view
local isLocked = false
-- Function to toggle the lock
local function toggleShiftLock()
isLocked = not isLocked
UIS.MouseBehavior = isLocked and Enum.MouseBehavior.LockCenter or Enum.MouseBehavior.Default
-- Hide mouse icon when locked
UIS.MouseIconEnabled = not isLocked
end
-- Listen for Controller Input
UIS.InputBegan:Connect(function(input, processed)
if processed then return end
if input.KeyCode == TOGGLE_BUTTON then
toggleShiftLock()
end
end)
-- Handle the Camera and Character Rotation
RunService.RenderStepped:Connect(function()
if isLocked and character:FindFirstChild("HumanoidRootPart") then
local rootPart = character.HumanoidRootPart
-- Force the mouse to stay centered
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
-- Rotate the character to face the same direction as the camera
local lookVector = camera.CFrame.LookVector
local newRotation = CFrame.new(rootPart.Position, rootPart.Position + Vector3.new(lookVector.X, 0, lookVector.Z))
rootPart.CFrame = newRotation
end
end)