Error: attempt to index nil with 'SetIsMouseLocked'

Hey! I’m just trying to force the player (this is a local script) to disable shiftlock (this is to avoid ragdoll system bugs related to camera) and keep getting that error (on the respective line).

LOCAL SCRIPT PART (player = local player):

local PlayerModule = player.PlayerScripts:WaitForChild("PlayerModule")	
local Cameras = require(PlayerModule):GetCameras()
local CameraController = Cameras.activeCameraController
CameraController.activeCameraController:SetIsMouseLocked(true)  --ERROR LINE
player.DevEnableMouseLock = false

Thank you for reading!

1 Like

That means that activeCameraController is nil.

2 Likes

I know that, but I’m trying to find out why is it nil, since that should be completely valid.

probably because you set CameraController to Cameras.activeCameraController, then you index that same key in the second line

Edit: also PlayerModule is a module and should be require()-d

3 Likes

I’m not familiar with Cameras.activeCameraController, so I’m going to ask. Is activeCameraController an object inside “Cameras” or a property?


probably because you set CameraController to Cameras.activeCameraController, then you index that same key in the second line

Oh wow- I did not notice that.

2 Likes

Fixed it and still getting the error :frowning:

Also, I’m using require() for PlayerModule on the “Cameras” variable.

Thank you for replying!

I don’t know either, there is no API reference or anything at all about it.

What is the purpose of requiring the PlayerModule

1 Like

Get the cameras, using:GetCameras().

Using GetCameras for what? if you need to disable shiftlock, you can go to Explorer → StarterPlayer → Find EnableMouseLockOption → Set it to false

1 Like

Apparently, activeCameraController is not just one function, its actually dynamic, and it can also be nil

1 Like

I want it to disable right at the moment in case the player has shift lock enabled.

So you’re telling me you disable the player’s shiftlock mid-game?

1 Like

Exactly! This is to prevent players to move using the shiftlock rotation while ragdolled.

I want to force the shiftlock disabling.

1 Like

Sorry! I just misclicked on the “Solution” button.

can you try this

local PlayerModule = player.PlayerScripts:WaitForChild("PlayerModule")	
local mouseLock = require(PlayerModule.CameraModule.MouseLockController)

mouseLock:EnableMouseLock(true) -- Set to true or false
player.DevEnableMouseLock = false

Also, what is the last line for?

1 Like

Last line is to disable MouseLock toggle, but I’ll try your solution.

wait, actually try this instead.

local PlayerModule = player.PlayerScripts:WaitForChild("PlayerModule")	
local mouseLock = require(PlayerModule.CameraModule).activeMouseLockController

mouseLock:EnableMouseLock(true) -- Set to true or false
player.DevEnableMouseLock = false
2 Likes

Yes, got a couple errors with the last code. I’ll try this one. Thank you for keep helping me.

image

Got this error on the mouseLock:EnableMouseLock(false) line :frowning:

1 Like