Force Shift lock using a script

i am trying to make a tool that forces shift lock when you equip it and goes back to normal when unequipped, but i cant figure out how to force shift lock. if anyone knows how to do this that would be great.

1 Like

maybe do UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter when equipping?

this worked but is there any way to get the offset and icon that shift lock gives.
i tried manually setting the humanoid cameraoffset but this doesnt function the same as the one shift lock uses as it doesnt force the character to look in the camera direction.
i also tried calling EnableMouseLock(true) on the MouseLockController module but it gave an error as regular scripts lack the capability to set DevEnableMouseLockOption.

lucky for you, i made my own custom shiftlock

local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local cha = plr.Character or plr.CharacterAdded:Wait()
local hrp = cha:WaitForChild("HumanoidRootPart")
local humanoid = cha.Humanoid

local camera = workspace.CurrentCamera

local uis = game:GetService("UserInputService")
local tweenserv = game:GetService("TweenService")
local run = game:GetService("RunService")



local isLocked = false

humanoid.AutoRotate = true


function shiftlock(active)
	local offset = Vector3.new(1.75,.25,0)
	if active then
		tweenserv:Create(humanoid,TweenInfo.new(.3,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{CameraOffset = humanoid.CameraOffset + offset}):Play()
		
		run.RenderStepped:Connect(function()
		uis.MouseBehavior = Enum.MouseBehavior.LockCenter
		
		humanoid.AutoRotate = false
		
		local _, y = workspace.CurrentCamera.CFrame.Rotation:ToEulerAnglesYXZ()
		hrp.CFrame = CFrame.new(hrp.Position) * CFrame.Angles(0,y,0)
		
		end)
		
	else
		tweenserv:Create(humanoid,TweenInfo.new(.3,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Position = camera.Position + offset}):Play()
		uis.MouseBehavior.Value = Enum.MouseBehavior.LockCenter

		humanoid.AutoRotate = true

	end
end

task.wait(3)
shiftlock(true)

basically, just shiftlock(true) if you want to enable it or shiftlock(false to disable it

1 Like

you script had a bunch of errors in it. the camera has no Position Property and you never disconnect the RenderStepped Connection. that being said i did fix it and whilst it did function as a shift lock it doesnt feel as fluid as the original as it is quite jagged.

i think im going to try use some form of coroutine to get a roblox core script to execute the shift lock switching on command using the MouseLockController Module, il let you know how that goes.
thanks for helping.

1 Like