Custom shift lock not allowing looking up/down

  1. What do you want to achieve? Keep it simple and clear!

a custom shift lock that can be toggled on my will

  1. What is the issue? Include screenshots / videos if possible!

the player can’t look up or down while its on.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

ive tried looking for working shiftlock scripts but to no avail, also tried developer discords, they don’t know whats up.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

--  LocalScript inside StarterPlayerScripts

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local ShiftLockEvent = ReplicatedStorage.Bindables.ShiftLockEvent

local function toggleShiftLock(active)
	local player = game.Players.LocalPlayer
	local char = player.Character
	if not char then return end

	local hum = char:FindFirstChildOfClass("Humanoid")
	local root = char:FindFirstChild("HumanoidRootPart")

	if not hum or not root then return end

	if active then
		hum.CameraOffset = Vector3.new(1.75, 0, 0) --  Offset for shift lock
		hum.AutoRotate = false

		--  Keep Mouse Centered & Lock Character Rotation Horizontally
		RunService:BindToRenderStep("ShiftLock", Enum.RenderPriority.Camera.Value, function()
			UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter

			local camera = workspace.CurrentCamera
			--local camRotation = camera.CFrame.Rotation 
			--local _, yRotation, _ = camRotation:ToEulerAnglesYXZ() 
			
			

			
			--root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0, yRotation, 0)
			
			local camLookVector = camera.CFrame.LookVector
			local horizontalDirection = Vector3.new(camLookVector.X, 0, camLookVector.Z).Unit

			root.CFrame = CFrame.new(root.Position, root.Position + horizontalDirection) 
		end)
	else
		hum.AutoRotate = true
		hum.CameraOffset = Vector3.new(0, 0, 0)
		RunService:UnbindFromRenderStep("ShiftLock")
		UserInputService.MouseBehavior = Enum.MouseBehavior.Default
	end
end

--  Listen for Shift Lock Event
ShiftLockEvent.Event:Connect(toggleShiftLock)

Video of bug

2 Likes

Fixed the issue, turns out i had some code in another script also manipulating the camera.

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