How can I force shift lock?

How do you put it in the code into the module…

Sorry 30 characters

1 Like

Go to line 468 where it says CameraModule:Update(dt) then type this line of code

self.activeCameraController:SetIsMouseLocked(true).

2 Likes

What I mean is how do you do that? I can’t find the script in the workspace, and to my knowledge, you can’t edit a script mid-game using another script

1 Like

Join The Game in studio and go into you player find a folder called player scripts and you will find a script called PlayerModule Copy that and exit the game session paste it in StarterPlayer → StarterPlayerScripts find Camera Module under that and then Go to line 468 where it says CameraModule:Update(dt) then type this line of code

self.activeCameraController:SetIsMouseLocked(true).
1 Like

I know this is from a really long time ago, but I have to say, I tried that method to add shiftlock aiming for guns and I was experiencing HUGE performance hindrances, and the hindrances got worse and worse the more time you spent in the game. This is because the :Update() function is called about once every 8 milliseconds or so, meaning, that if you set connections like I did (To make it detect when a weapon is equipped) It will make thousands of connections to the RBXScriptSignal. The fix was very simple. Outside of the function, I set a variable called “connected” to false, and had an if statement inside of the function saying if connected == false then [I put the stuff I wanna happen here] end, and I put connected = true inside of it. If anyone is going to use this method for connections, you must use this method, otherwise there will be a huge amount of lag.

2 Likes

I’ve never experience major performance hits using this, but it never stops helping to improve! I’ve noticed that in studio sometimes it lags more than actual gameplay so I’ve been using a mix of both to test my game, my fix was more of a quick workaround as well so I didn’t really plan for optimizations as I never personally experienced any.

Were you using [RBXScriptSignal]:Connect() Inside of the update function? Also, if you have a powerful gaming laptop/PC, and your tests aren’t too long, you won’t notice the lag, but players with lower-end devices going for longer playsessions will experience it alot.

I made this when I had a less powerful PC and I rarely ran into any lag issues atleast from my testing, I used to sit in some of my games to think about what I would program next, and no, you should NEVER use a connect in a loop.

1 Like

But were you setting up Event connections?

Was editing my post, no that’s a horrible idea.

1 Like

Yeah, it is a bad idea usually, but if you use a true/false variable, you can make it set up the connections only once.

1 Like

As I said anything you can do to improve is good, just from my own testing when I used it i never had any major issues regarding the update function, as long as you didn’t put like something that eats power for breakfast, of course now my pc is a bit more up to date, I don’t run into those issues as much so it would be hard to test with more strenuous code on my part as my computer can do more calculations.

1 Like

Hi @skppiy4000, sorry for asking for help in a really old post, but I have no idea on how to disable shift lock after forcing it, I tried using Mystifine s solution but it only had the enabling option working.

Unfortunately alot of this stuff relied on old functionality of the camera, I did not test on the newer camera, knowing this, if you scroll up a bit I put a old version of the camera that would work, you just need to modify it to your needs so you can turn it on and off when needed, or scan through it and yoink what you need.

If you mean how to turn off toggling it once its on, I believe if you flick this, this should stop shift lock from being able to be activated. image

Hi again skppiy, thanks for the reply, turns out that the only thing I needed to do was make a function so that a variable which stores the current state of the players shift lock could be changed

I’ve found a solution to make the shift lock togglable and it seems to actually be working pretty good for me.

Here’s what I did:
For starters I wanted the shiftlock to toggle whenever I set a certain boolean to true, so I created a folder in StarterPlayerScripts with the boolean inside
image

After this I needed to make it actually do something, so I created a local script inside of StarterCharacterScripts and set it up so that on every frame it checks to see if the boolean is set to true or not, and sets a customized offset. I decided to do it like this because I needed to be able to adjust it later on and give myself more customization.

Here is an edited version of that script with the basic premise of it (I have since far edited it with more parts to it, I’m only here to show how to make the shift lock)

--[[SERVICES]]--
local runService = game:GetService("RunService")
local players = game:GetService("Players")

--[[VARIABLES]]--
--Player Variables--
local player = players.LocalPlayer
local humanoid = player.Character.Humanoid

--Camera Variables--
local originalCameraOffset = Vector3.new(0,0,0) --The original camera offset we want
local cameraOffset = Vector3.new(2,0,0) --Offset we want the camera to be set at when shift locked

--Shiftlock Variables--
local valueFolder = player.PlayerScripts.Values
local shiftLockOn = valueFolder.ShiftLock

local function shiftLockSetup()
	if shiftLockOn.Value == true then
		humanoid.CameraOffset = cameraOffset
	else shiftLockOn.Value == false  then
		humanoid.CameraOffset = originalCameraOffset
	end
end

runService.RenderStepped:Connect(shiftLockSetup)

Awesome, we have our offset working. The problem we have now is locking the mouse to the camera.
There are other ways to do this, but I chose to directly modify the Camera Module to lock the mouse to the character whenever the boolean is turned on, specifically line 469 in the CameraModule:Update() function. Here is the code snippet I used to replace the previous one.

function CameraModule:Update(dt)
	if self.activeCameraController then
		if shiftLockBool.Value == true then --Edited code, simple if-else statement
			self.activeCameraController:SetIsMouseLocked(true) --locks mouse to player
		else
			self.activeCameraController:SetIsMouseLocked(false)
		end
		if FFlagUserCameraToggle then
			self.activeCameraController:UpdateMouseBehavior()
		end

		local newCameraCFrame, newCameraFocus = self.activeCameraController:Update(dt)
		self.activeCameraController:ApplyVRTransform()
		if self.activeOcclusionModule then
			newCameraCFrame, newCameraFocus = self.activeOcclusionModule:Update(dt, newCameraCFrame, newCameraFocus)
		end

		-- Here is where the new CFrame and Focus are set for this render frame
		game.Workspace.CurrentCamera.CFrame = newCameraCFrame
		game.Workspace.CurrentCamera.Focus = newCameraFocus

		-- Update to character local transparency as needed based on camera-to-subject distance
		if self.activeTransparencyController then
			self.activeTransparencyController:Update()
		end
	end
end

I defined the shiftLockBool at the beginning of the module script.

Now, what this is doing is every time the camera is updated now if that boolean is set to true it will automatically lock the mouse, with the best part being the character will now move with the mouse.

When the these two scripts are put together now, the boolean will toggle shiftlock.

Best part about this is you don’t need to rescript an entire complicated thing for rotating the character around with the camera or write any complicated scripts, Roblox has already done half of it for you. On top of this this will always work, even if the toggle shiftlock option is turned off in game, allowing you complete control over shiftlocking the camera, and even on top of that this works on all platforms.

Hope this helped, there are likely better solutions but I’ve found this method has worked the best for me.

1 Like

This locks the mouse at the center, but unfortunately it doesn’t give the full-on feeling of shift lock. It doesn’t rotate the whole character onto where the camera is facing.

1 Like

It is indeed a very nice working method, but I’m experiencing some issues with it. The camera is constantly rotating in the direction where the mouse last moved to. Any Idea of what could be causing this?

What do you mean by it’s constantly rotating to where the mouse last moved to? Can you send a video of it?

1 Like

Sorry for resurrecting this thread but here’s a video of what’s happening. There’s like a permanent mouse acceleration kind of thing going on

2 Likes