local players = game:GetService("Players") local runService = game:GetService("RunService") local userInputService = game:GetService("UserInputService") local localPlayer = players.LocalPlayer local character = localPlayer.Character or localPlayer.CharacterAdded:Wait() local root = character:WaitForChild("HumanoidRootPart") local humanoid = character:WaitForChild("Humanoid") local camera = workspace.CurrentCamera local iconOff = "rbxassetid://77288664952024" local iconOn = "rbxassetid://140416355442805" local cursorImg = "rbxasset://textures/MouseLockedCursor.png" local isTouchDevice = userInputService.TouchEnabled local screenGui = Instance.new("ScreenGui") screenGui.Name = "shiftlockgui" screenGui.ResetOnSpawn = false screenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling screenGui.IgnoreGuiInset = true screenGui.Parent = localPlayer:WaitForChild("PlayerGui") local customIconId = "" local customCursorId = "" if customIconId ~= "" then iconOff = customIconId iconOn = customIconId end if customCursorId ~= "" then cursorImg = customCursorId end local buttonPosition = UDim2.new(0.86, 0, 0.93, 0) local buttonSize = UDim2.new(0, 44, 0, 44) local button = Instance.new("ImageButton") button.Name = "shiftlockbutton" button.Size = buttonSize button.Position = buttonPosition button.AnchorPoint = Vector2.new(0.5, 0.5) button.Image = iconOff button.BackgroundTransparency = 1 button.BorderSizePixel = 0 button.ImageRectSize = Vector2.new(0, 0) button.Visible = isTouchDevice button.Parent = screenGui local cursorSize = UDim2.new(0, 25, 0, 25) local cursor = Instance.new("ImageLabel") cursor.Name = "shiftlockcursor" cursor.AnchorPoint = Vector2.new(0.5, 0.5) cursor.Position = UDim2.new(0.5, 0, 0.5, 0) cursor.Size = cursorSize cursor.BackgroundTransparency = 1 cursor.BorderSizePixel = 0 cursor.ScaleType = Enum.ScaleType.Fit cursor.Image = cursorImg cursor.Visible = false cursor.Parent = screenGui local shiftLockActive = false local renderConnection local shoulderOffset = CFrame.new(1.7, 0, 0) local maxLength = 999999999 local function updateButton(state) button.Image = state and iconOn or iconOff end local function getFacingCFrame() return CFrame.new( root.Position, Vector3.new( root.Position.X + camera.CFrame.LookVector.X * maxLength, root.Position.Y, root.Position.Z + camera.CFrame.LookVector.Z * maxLength ) ) end local function enableShiftLock() humanoid.AutoRotate = false updateButton(true) userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter userInputService.MouseIconEnabled = false cursor.Visible = true renderConnection = runService.RenderStepped:Connect(function() root.CFrame = getFacingCFrame() camera.CFrame = camera.CFrame * shoulderOffset camera.Focus = CFrame.fromMatrix( camera.Focus.Position, camera.CFrame.RightVector, camera.CFrame.UpVector ) * shoulderOffset end) end local function disableShiftLock() humanoid.AutoRotate = true updateButton(false) userInputService.MouseBehavior = Enum.MouseBehavior.Default userInputService.MouseIconEnabled = true cursor.Visible = false if renderConnection then renderConnection:Disconnect() renderConnection = nil end end local function toggleShiftLock() shiftLockActive = not shiftLockActive if shiftLockActive then enableShiftLock() else disableShiftLock() end end button.MouseButton1Click:Connect(toggleShiftLock) localPlayer.CharacterAdded:Connect(function(newCharacter) character = newCharacter root = newCharacter:WaitForChild("HumanoidRootPart") humanoid = newCharacter:WaitForChild("Humanoid") if renderConnection then renderConnection:Disconnect() renderConnection = nil end shiftLockActive = false updateButton(false) cursor.Visible = false userInputService.MouseBehavior = Enum.MouseBehavior.Default userInputService.MouseIconEnabled = true end) players.PlayerRemoving:Connect(function(leavingPlayer) if leavingPlayer == localPlayer and shiftLockActive then disableShiftLock() end end)