#Shift Lock

1 messages · Page 1 of 1 (latest)

midnight dove
#

Im working on a game and trying to make a custom script to enable and disable Shift Lock using a different key im confused cause in the docs it said something about a previous way being depricated in the mean time ive got something working where it uses mouse lock but is it as good as shift lock and is there a way to use shift lock that wont have a chance of getting broken in the future due to things changing

pale valve
#
local shiftLock = script.Parent:WaitForChild("PlayerModule"):WaitForChild("CameraModule"):WaitForChild("MouseLockController")

Control:WaitForChild("BoundKeys").Value = "LeftControl"
#

this is my script

#

just replace "LeftControl"

#

with the keybind youw ant

midnight dove
# pale valve what key do you want it to be

i used this for a little but i was worried about it breaking if they ever change it should i be worried or is it a dumb fear this is what im using currently and it works perfectly fine i think the built in shift lock may just be better though or am i also wrong about that

-- Shift Lock to Left Alt
local function onInput(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.LeftAlt and UserInputService.MouseBehavior == Enum.MouseBehavior.Default then
        print("Shift Lock Enabled") -- For Debugging
            UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
    elseif input.KeyCode == Enum.KeyCode.LeftAlt and UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter then
        print("Shift Lock Disabled") -- For Debugging
            UserInputService.MouseBehavior = Enum.MouseBehavior.Default
    end
end

UserInputService.InputBegan:Connect(onInput)```
pale valve
#

prob easier

#

if you want it on left alt

#

its not that hard

midnight dove
#

did you look at what i sent?

pale valve
#
local shiftLock = script.Parent:WaitForChild("PlayerModule"):WaitForChild("CameraModule"):WaitForChild("MouseLockController")

Control:WaitForChild("BoundKeys").Value = "LeftAlt"
pale valve
#

so

#

up to you tbf

#

both work

#

id use the built in one

#

personally

midnight dove
#

are you able to change the look of the built in one

primal gullBOT
#

studio** You are now Level 2! **studio

midnight dove
#

if you know

pale valve
#

in what way?

#

the image in the middle?

midnight dove
#

yeah

#

id like to make it custom if possible

#

if not ill stick to this one which should let me change the cursor icon when activated

pale valve
#

you would probably have to keep the same script in that case

#

i dont believe you can change it

midnight dove
#

alright well appreciate the help

#

one more question

#

how can i disable the original shit lock

pale valve
#

enable mouselockoption

#

you could just do it in ur script tbg

#

but this works

midnight dove
#

preciate it sm

pale valve
#
local starterPlayer = game:GetService("StarterPlayer")
starterPlayer.EnableMouseLockOption = false
#

more hassle than its worth

#

but its an option

pale valve
#

good luck with your creations!

pale valve
#

@midnight dove

primal gullBOT
#

studio** You are now Level 13! **studio

pale valve
#

update

#

you actually can change the image

#
local Control = script.Parent:WaitForChild("PlayerModule"):WaitForChild("CameraModule"):WaitForChild("MouseLockController")

Control:WaitForChild("BoundKeys").Value = "LeftControl"
Control:WaitForChild("CursorImage").Value = "rbxassetid://5801470647"
midnight dove
# pale valve update

i appreciate i actually already fully custom made mine so its cool it probably wouldve been easier to use default but mine also allows me to check if its on or off and do custom things with it like also things like camera smoothing and ect ect

pale valve
#

im interested in how you did it

midnight dove
#
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

-- check to use for other scripts
local isShiftLockEnabled = false

RunService.RenderStepped:Connect(function()
    local character = LocalPlayer.Character
    if not character then return end

    local hrp = character:FindFirstChild("HumanoidRootPart")
    local head = character:FindFirstChild("Head")
    local neck = head and head:FindFirstChild("Neck")
    local humanoid = character:FindFirstChildWhichIsA("Humanoid")

-- makes sure camera follows like original shift lock not just locking mouse to middle of screen
    if isShiftLockEnabled and hrp then
        local cam = workspace.CurrentCamera
        local lookVector = Vector3.new(cam.CFrame.LookVector.X, 0, cam.CFrame.LookVector.Z).Unit
        hrp.CFrame = CFrame.new(hrp.Position, hrp.Position + lookVector)
        if humanoid then
            -- makes body stop moving
            humanoid.AutoRotate = false
        end
    end
end)

-- Keybind
local function onInput(input, gameProcessed)
    if gameProcessed then return end

    if input.KeyCode == Enum.KeyCode.LeftAlt then
        isShiftLockEnabled = not isShiftLockEnabled
        print("Shift Lock", isShiftLockEnabled and "Enabled" or "Disabled")

        UserInputService.MouseBehavior = isShiftLockEnabled and Enum.MouseBehavior.LockCenter or Enum.MouseBehavior.Default

        local character = LocalPlayer.Character
        if character then
            local humanoid = character:FindFirstChildWhichIsA("Humanoid")
            if humanoid then
                humanoid.AutoRotate = not isShiftLockEnabled
            end
        end
    end
end

UserInputService.InputBegan:Connect(onInput)
#

also if you have any advice let me know or even any questions im always open to learning

#

@pale valve

pale valve
midnight dove
pale valve
midnight dove
#

wait now im confused holdon

pale valve
midnight dove
#

what do you mean exactly

#

by side?

pale valve
#

like yk when you shiftlock, the camera goes to the side

#

that

midnight dove
#

OHHHHH the offset

#

yeah

pale valve
#

yeah offset

midnight dove
#

no i could definitely do it but and im debating on if i want to but i may not

pale valve
#

fair enough