Enable shiftLock error

I am trying to activate shiftLock when the player clicks the mouse button but I keep getting this error: “attempt to call a nil value” when I try to require the cameraMoudle (line 2).
the LocalScript :

local plr = game.Players.LocalPlayer
local CameraModule = require(plr.PlayerScripts.PlayerModule.CameraModule).new()
local MouseLockController = CameraModule.activeMouseLockController
local shiftLockConn

function shiftLock(active) --Toggle shift lock function
        shiftLockConn = game:GetService("RunService").RenderStepped:Connect(function()
			MouseLockController:DoMouseLockSwitch(0, Enum.UserInputState.Begin) --enable the LockSwitch
		end) 
end
local function onInputBegan(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		shiftLock(true)
	end
end
UserInputService.InputBegan:Connect(onInputBegan)
plr.PlayerScripts.PlayerModule.CameraModule

This must be nil, perhaps try adding waits.

I tried to add wait Still not working, it’s not nil if I remove the new() and there was no error in this line, the error will be in “MouseLockController:DoMouseLockSwitch(0, Enum.UserInputState.Begin)” (line 7).

MouseLockController.DoMouseLockSwitch(0, Enum.UserInputState.Begin)

Should you be using the dot operator instead of colon? I’m unfamiliar with this module.

I don’t think I tried it still getting the same error

I solve the problem by adding a BodyGyro

1 Like

how you solved it?
can you teach me and i can pay you?