Fore shift lock with default module

Can I change the code of the default camera module script somehow?

What I want to do is force/toggle the mouse lock option with the default camera module. Would I be able to do this without needing to recreate the camera module?

There is a post that might solve your problem

I know about that thread. Do you happen to know what the guy who answered it is talking about. Like, where do I put the code he is talking about?

It says " Unknown global ‘self’ "

Yea I deleted it because I realized it needs to be put in some kind of camera module.

Do you know how to do that by any chance?

Just did some researches, try this one in a local script

local PlayerModule = game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule")
local cameras = require(PlayerModule):GetCameras()
local BoundKeys = PlayerModule.CameraModule.MouseLockController:WaitForChild("BoundKeys")
local OldBoundKeys = BoundKeys.Value

local CenterLocked = false
local function ToggleLock()
	local CameraController = cameras.activeCameraController
	local MouseLockController = cameras.activeMouseLockController
	CenterLocked = not CenterLocked
	if CenterLocked then
		if MouseLockController:GetIsMouseLocked() then -- toggle shift lock off
			MouseLockController:OnMouseLockToggled()
		end
		CameraController:SetMouseLockOffset(Vector3.new())
		CameraController:SetIsMouseLocked(true)
		BoundKeys.Value = "" -- disables shift lock toggle
	else
		CameraController:SetIsMouseLocked(false)
		BoundKeys.Value = OldBoundKeys -- restores shift lock toggle
	end
end

-- example use, press T to toggle center lock
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then return end
	if input.KeyCode == Enum.KeyCode.T then
		ToggleLock()
	end
end)

Also here’s the link:

1 Like

It says that MouseLockController is nil.

You must fork PlayerModule (module script) what that means is you copy that module script called PlayerModule how you do that is after playing game in studio you then look for Players in Explorer like so Players/YourPlayerName/PlayerScripts then copy PlayerModule from there. Then you stop the game and paste that module script inside StarterPlayer/StarterPlayerScripts. Now after that you must look for the CameraModule under PlayerModule then click on that module script to view the code inside then search for Update function you can do that by pressing ctrl+f then type that Update word look untill you find the function called CameraModule:Update(dt) then you put this line of code inside self.activeCameraController:SetIsMouseLocked(true)

2 Likes