Force Shift Lock (Using Player Module)

Recently, I was looking for a way to force shift lock in Roblox. I tried several methods without using the player module, but none of them provided a smooth experience. After searching for methods involving the player module, I couldn’t find much information. However, I eventually devised a solution using a combination of approaches.

Steps to Force Shift Lock

  1. Modify the Camera Module:

    In the CameraModule, within the .new function, add the following line to initialize the custom lock:

    self.CustomLock = true
    

    Setting it to true ensures that players are forced into shift lock upon spawning.

  2. Update the Camera Controller:

    In the :Update function within the CameraModule, add this line of code to apply the custom lock setting:

    self.activeCameraController:SetIsMouseLocked(self.CustomLock)
    
  3. Create a ToggleShiftLock Function:

    Next, create a function within the CameraModule to toggle the shift lock:

    function CameraModule:ToggleShiftLock(Var)
        self.CustomLock = Var
    end
    
  4. Add a ForceLock Function to the Player Module:

    In the PlayerModule, create a function to force the shift lock:

    function PlayerModule:ForceLock(var)
        self.cameras:ToggleShiftLock(var)
    end
    

Example of Using the ForceLock Function

To call the ForceLock function, you can use the following code:

local playerModule = require(localPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule")).new()
playerModule:ForceLock(true)

Additional Fixes

To address some issues that might arise, you can add these lines of code after forcing the lock:

[HUMANOID_VAR].CameraOffset = Vector3.new(1.75, 0, 0)
UserInputService.MouseIconEnabled = false

Replace [HUMANOID_VAR] with the variable representing the player’s humanoid.

Unlocking

To Unlock the player you will need to Call the ForceLock function with false, enable the Mouse icon and reset camera offset. An example is:

playerModule:ForceLock(false)
[HUMANOID_VAR].CameraOffset = Vector3.new(0,0,0)
UserInputService.MouseIconEnabled = true

Summary

By following these steps, you can force shift lock for players using a combination of modifications in the camera and player modules. This method provides a smooth experience and ensures that shift lock is consistently applied.

Note: if you have any improvements please reply with them


7 Likes

Nice tutorial!

Forces the real roblox shiftlock, not toggleable sadly but just incase you’re looking for permanent force shiftlock, i’ve been looking for this a while ago

1 Like

Can’t we just do:

game:GetService("UserInputService").MouseBehaivour = Enum.MouseBhaivour.LockCenter
1 Like