How can I force shift lock?

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

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…

image
DOESNT WORK.

image
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!

1 Like

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