Error: attempt to index nil with 'SetIsMouseLocked'

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
1 Like

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

can you tell me what this prints, and also after the wait(1)

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

Edit: what if you just tried this

player.DevEnableMouseLock = false
1 Like

Both of them are nil.

If I only use DevEnableMouseLock then if the player already had the shiftlock enabled, it won’t be disabled (DevEnableMouseLock only enables/disables the toggle function).

1 Like

CameraModule:GetCameras() returns a blank table right now, there are no members (properties or functions). You will need to explicitly fork CameraModule to return the Camera singleton.

3 Likes

so you can just copy the PlayerModule then paste it into the StarterPlayerScripts and it works?

1 Like

Correct. Roblox will not inject the default PlayerModule if you include one in StarterPlayerScripts, so the PlayerScriptsLoader that gets injected will see and require your fork instead of a PlayerModule also injected by the client at run time.

2 Likes

So I should just remove the “return cameraapi” line?

Alright, then @HaxxerVaxxer can just download this file and paste it into StarerPlayerScripts right?
PlayerModule.rbxm (108.5 KB)
I just saved the PlayerModule to file then pasted it here

1 Like

Ok, what if you download that file, paste it into StarterPlayerScripts then tried this code

what prints?

1 Like

Same (nil, nil). I already had PlayerModule in StarterPlayerScripts. What does it mean a module to be “forked”?

take the code then modify it or whatever you want to do. What i told you to do is fork the PlayerModule (copy it then paste). Then require that forked module instead of the Default module

1 Like

I did what @colbert2677 said and it worked perfectly (also, I used my old script).
Anyways, thank you for really trying to help me!

1 Like