How can I force shift lock?

you can set them both to the same value so the player is locked in third person and can’t zoom in-out?

4 Likes

That locks player into third person, but if the mouse is in the center of the screen, the player will be in the center. I want an over the shoulder type camera.

1 Like

Use a localscript to access the humanoid in the player character, then in “CameraOffset” set the value of X to 1 or 2, that will have it on the shoulder instead of centered, sorry I was on a trip for a day and couldn’t answer back.

9 Likes

Thanks, that fixed it for me! It works perfectly now!

2 Likes

Sorry for bumping this old thread. But I didn’t quite get your explanation.

Should I have a script like this inside a local script in StarterPlayerScripts:

plrModule = script.Parent:WaitForChild("PlayerModule")
CameraModule = require(plrModule.CameraModule)



function CameraModule:Update(dt)

self.activeCameraController:SetIsMouseLocked(true)

end

I dont get any errors. But it doesnt do anything either.

3 Likes

Unfortunately this method relied on how the older camera scripts worked, and I think they changed a few things, I made this a while back while I was using it for my own game, but I decided to fish out my old games camera script and slightly document controls, it really was only a few adjustments, but for your use you’ll have to adjust it a bit more to your games liking, you may not be able to go to your ESC menu in studio but it should work in actual gameplay. https://www.roblox.com/library/5173113621/Force-Shiftlock-Forked-Playermodule

(Install into StarterPlayerScripts)

It’s most likely possible to do this with newer player camera scripts, but I have not been experimenting as I haven’t needed to for a while, this can be a temp fix and solution for any forced camera games, feel free to modify and even expand on it if you want, anyone who wants it can have it… enjoy! (Let’s hope one day we get official support for this so we don’t have to fork default roblox scripts :wink: )

10 Likes

Thanks for the long and extensive answer!

Sorry, but, it turns out I tried it in the totally wrong way. I was unaware that the self.activeCameraController:SetIsMouseLocked(true) was supposed to be inside the CameraModule :expressionless:

and when I did what you said (see picture) it worked perfectly.

However, if you could help me with one last thing, that would be great.

So, now, I have the problem that I cannot turn shiftlock on and off. So, when I start the game, shiftlock force is on and will not be disabled.

So, I was wondering, is there any way to implement or to call this function form a local script inside for example, a weapon?

Because, I would like force shiftlock only to be enabled when a weapon is equipped. Or, in general, that I can turn it “On” and “off”.

I am not very experienced with roblox core script modifications and other module scripts in general.

Do you think there is a way to fire that function from a local script turning force shift lock on and off?

Thank you very much for your help so far, and looking forward to your answer.

Sincerely.

Edit 1:

Can I use a remote event to fire that one specific function inside the module script? See picture.

Edit 2:

I used your model that you sent me, it works like a charm. But, if I didn’t misread, is it possible to fire shiftlock on/off here:


Or did I interpret the “conditional” wrong… thanks.

2 Likes

I want to give thanks to @EDmaster24 for figuring this out.

The module that actually is responsible for shift lock is MouseLockController, which is in Player > PlayerScripts > PlayerModule > CameraModule > MouseLockController

So to Enable shift lock, what you need to do is get a copy of the PlayerModule. Which you can obtain after press Play and copying it from PlayerScripts. After you’ve done so, place the PlayerModule in StarterPlayerScripts. Once you’ve done this, open up the camera module.


https://gyazo.com/f4312e1e90f76ec951cebfbd26e7eff8

In here you want to add a function like so:

function CameraModule:ToggleShiftLock(Enable, ModifiedVar, Modifier)
	self.activeMouseLockController:EnableMouseLock(Enable,ModifiedVar,Modifier)
end

So to explain this function, the first argument Enable determines whether or not the player is able to press Shift to disable/enable the shift lock again.

The second argument ModifiedVar determines if you are going to use the third one the Modifier. And the Modifier determines if you are using something else.

NEXT you’re going to need to edit the EnableMouseLock method in MouseLockController, so open that up and head to here:


https://gyazo.com/16c8827528e0f0ff6e2c62082030a4be

What you want to do is you want to swap that out for this:

LASTLY you want to backtrack to the PlayerModule and add this:


https://gyazo.com/840d126f3160cb7060fe72f8be0bb5e9

Right on top before it’s returned. And you’re done!

So to toggle the shift lock what you’re going to need to do is in your local script, require the PlayerModule. And then you can use the function.

local Player = game.Players.LocalPlayer
local PlayerModule = require(Player:WaitForChild"PlayerScripts":WaitForChild"PlayerModule")

PlayerModule:ToggleShiftLock(false, true, true) -- This will force it into shift lock.
PlayerModule:ToggleShiftLock(true, false, false) -- This will make it so the player is able to toggle their shift lock again

I’ve been looking into this topic for hours and I definitely want to share this piece of information to those who are still searching for a way to force shift lock.

EDIT: So there seems to be a few errors, first off in the CameraModule you want to head to the end of the script here:

https://gyazo.com/b68235325d52c54cce7b99834b9c5b71

and replace it with this:

https://gyazo.com/980a1f3a1c750becd1c18749b45b738c

31 Likes

Using some the uncommented things, you can setup some conditions for it to unlock like menus/pressing shift, you just have to find a way to inform the script, that’s how I setup conditions when I had my characters sprint, I didn’t go into too much detail tho past that as I fished it out and made it usable quick, or you can just do what was above maybe =) it might be better if you can use newer camera scripts, mine was just a workaround at the time.

2 Likes

Hello, thank you so much for sharing this bit of information! It will help me tons and tons and tons on my upcoming game. I am very gratefull! Thank you.

I am sure this works (as it obviously has for you) but I think that I have made a silly mistake somewhere in the code. And I can’t figure it quite out.

So, I (think) did follow your instructions on the code change etc. And to test it out, I just put a local script inside the “StarterPack”.

But I get this error:

Players.Oficcer_F.PlayerScripts.PlayerModule:33: attempt to call a nil value

As I am not particularly informed nor good at module scripts I have spent a pretty long period of time to debug it. But I just can’t figure it out, as my base knowledge of ModuleScripts is not good enough.

I just had a quick question, if you could take a quick look at the code and the game? And try to find the error? I am sure it is just a silly typo or something, but hey, it always helps when you get another pair of eyes on a problem.

I would be beyond grateful if you could help me! Thank you very much!

Here is the file:
CameraError.rbxl (127.2 KB

Again, thank you!

2 Likes

So I took a look and it seems like the error is due to the last part returning an empty table which has no functions in it at all. I’ve edited my original reply and made fixes and changes since some parts of the code were also not right.

Here you go (This is a fixed version):
CameraError.rbxl (127.5 KB)

If you were to follow the steps again it should be correct now. Thanks for mentioning it didn’t work.

1 Like

Thank you very much for your quick reply.

I downloaded the fixed version you sent me, but it still doesn’t work.

I get 0 errors and it also prints “A” (after calling to force shift lock)

Is there an error, or am I doing something wrong?

Thanks

1 Like

Is there anything in the output? It should be working, I’ve tested it earlier and it was working fine.

1 Like

Nothing in the output other than «A» (which means it should be working?) …

And also, do I need to enable shiftlock or any other setting?

It’s really weird. I will make a closer investigation tomorrow and will say if it worked or not!

Thank you very much so far!

1 Like

I believe you do need to give the player the option to shiftlock by default.

1 Like

I just want to test if this solution would work as i see this has already been solved. Try this

local UserInputService = game:GetService("UserInputService")
 
-- Shift keys
local shiftKeyL = Enum.KeyCode.LeftShift
local shiftKeyR = Enum.KeyCode.RightShift
 
-- Return whether left or right shift keys are down
local function IsShiftKeyDown()
	return UserInputService:IsKeyDown(shiftKeyL) or UserInputService:IsKeyDown(shiftKeyR)
end
 
-- Handle user input began differently depending on whether a shift key is pressed
local function Input(input, gameProcessedEvent)
	if not IsShiftKeyDown() then
		-- Normal input
	else
		-- Shift input
	end
end
 
UserInputService.InputBegan:Connect(Input)

--Now add either the ShiftKeyR or ShiftKeyL depending on which one you want locked and it should look something like this:

while 2+2 == 4 = true do
ShiftKeyL = true
end
1 Like

To me, this looks like the worst loop of all time. It would probably error as well,. Instead, just do a while true do loop.

3 Likes

oh, . . . i didnt know you can just say true. sorry

3 Likes

Hey, I found the error. So the problem was that I hadn’t enabled the shift lock switch to “On”.

But, my problem now is that: When the shift lock switch is turned to “Off”. The script won’t work.

So, how would I go about that? Or how could I force it to stay on etc.

I have seen some games with: Shiftlock set by developer. Is there any way that I can switch that on or something like that?

1 Like

If you want shiftlock to be unable to be changed by the client, you can head to StarterPlayer and uncheck this property:

https://gyazo.com/994b17999049d1ae7223104865b67856

1 Like