How can i force shiftlock through PlayerModule? I wanted to make an aim system with a gun, I’ve made already a sort of custom shiftlock, then i thought why not forcing roblox shiftlock when aiming with the gun so I can also make the crosshair appear easily just as a cursor image.
I’ve tried to search online, also read some post on this forum, however any of them do not work.
I’d like to see if there’s any solution. By your opinion is it worth it, or is it just better trying to make a custom one?
I skimmed through the entire current version of the PlayerModule hierarchy, and it’s IMPOSSIBLE to do it without overwriting the PlayerModule.
The only way is to change a SINGLE line of code in CameraModule. Simply move CameraModule.new() to where return is, exactly as shown in the screenshot.
Then you can set the shiftlock state using the CameraModule’s MouselockController & manually update it visually & functionally.
-- You can copy+paste all of this to a LocalScript.
local player = game:GetService("Players").LocalPlayer
local CameraModule = require(player.PlayerScripts.PlayerModule.CameraModule)
local MouselockController = CameraModule.activeMouseLockController
local function ToggleShiftlock(enabled: boolean)
if MouselockController.isMouseLocked == enabled then return end
MouselockController:OnMouseLockToggled()
end
-- Example usage
local enable = false
while true do
enable = not enable
ToggleShiftlock(enable)
print(enable)
task.wait(2)
end
Here is a file if you’re too lazy to do it yourself, just put this in StarterPlayerScripts. Just keep in mind that the PlayerModule will occasionally update, so just literally grab the new version & change that single line of code if you want to update it. CustomShiftlockToggle.rbxm (138.7 KB)
Making this a resource real quick if nobody has caught onto this yet.
You can force Shift Lock through PlayerModule with a BindableEvent.
Reference:
Copy PlayerModule into StarterPlayerScripts, add a BindableEvent named ShiftLock_Event, then make CameraModule listen to it and call OnMouseLockToggled(true/false).