I cannot seem to find any way to Detect if ShiftLock is enabled without using MouseBehaviour. My 100% scripted camera manually sets MouseBehaviour so using MouseBehaviour is useless bc if the zoom is 0 then its forced to be on and else then its off I wanna be able to detect shift lock without the MouseBehaviour.
It’s possible that I’m overlooking a simpler way of accessing this information, but it seems like “Shift Lock” is implemented entirely via Lua in the default player control scripts. To access this information, the default CameraModule
will need to be forked.
If you already know how to fork the default player scripts, you can skip this paragraph, but if you don’t know, you do this by “running” the game and copying the PlayerModule
that shows up in StarterPlayer.StarterPlayerScripts
. Stop the game and paste these scripts back into the StarterPlayer.StarterPlayerScripts
folder. From now on, when you run the game, your game will use these scripts instead of the default ones.
The lines you need to change are in the CameraModule
module at the very end. Replace the following lines…
local cameraModuleObject = CameraModule.new()
local cameraApi = {}
if FFlagUserRemoveTheCameraApi then
return cameraApi
else
return cameraModuleObject
end
…with just…
return CameraModule.new()
This will expose the camera controllers when you access the object returned when you require
the top-level PlayerModule
module, meaning you can connect to the event that triggers when a player toggles “Shift Lock” as well as read the value it is set to. This code snippet demonstrates how to do so and will print whether or not “Shift Lock” is on every time the player toggles the script.
local player_object = require(game:GetService("Players").LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule"))
local shift_lock_controller = player_object:GetCameras().activeMouseLockController
local shift_lock_on
shift_lock_controller.mouseLockToggledEvent.Event:Connect(function(state)
shift_lock_on = shift_lock_controller:IsMouseLocked()
print("SHIFT LOCK TOGGLED:",shift_lock_on)
end)
Again, this method works, but I don’t know if it is the only/best method, since it requires forking the control scripts.
This method is simpler but can have a flase positive if somthing else is changing the mouse icon to the ShiftLock icon.
local Mouse = game:GetService("Players").LocalPlayer:GetMouse()
Mouse:GetPropertyChangedSignal("Icon"):Connect(function()
if Mouse.Icon == "rbxasset://textures/MouseLockedCursor.png" then
print("Shift lock just got enabled!")
end
end)
I just had a 100% scriptable method and implemented it so its fine now
thats a nice solution but i use a metatable mouse so using getpropertychangedsignal wont work.