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.
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.
Thanks, that fixed it for me! It works perfectly now!
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.
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 )
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
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.
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
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.
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!
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.
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
Is there anything in the output? It should be working, I’ve tested it earlier and it was working fine.
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!
I believe you do need to give the player the option to shiftlock by default.
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
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.
oh, . . . i didnt know you can just say true. sorry
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?
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
Hey, thanks for the answer!
I unchecked that property, but now my problem is that it doesn’t force it.
So, what the script does now is to allow me to enable shiftlock and disabling it by pressing shift.
Basically, shiftlock is turned off and when this part comes:
nothing happens
and then when the part comes that should disable forced shiftlock:
It gets ENABLED - not forced, but I again, get the posibility to toggle the shift lock by pressing shift.
But not forced, it just lets me enable it.
Is there any way that I can force the shiftlock thing to “On” and it is not possible to change it?
Look at this video for a better understanding!
https://vimeo.com/430316711
This happens when I have the enable mouse lock option set to false. If I have it set to true it works.
But the player needs to have the shiftlock option to “On” and not “Off”. So, if players have it set to “Off” they will bypass the whole thing and essentialy destroy the games experience…
DOESNT WORK.
WORKS
Sorry for beeing so “asky”.
How did you do it in your game @Mystifine?
I am very gratefull for all the help so far!