How to force shift lock when player holds tool?

Hey developers!

So yea, basically the title…

How could I force a player into shift lock when they hold a tool, then take them out of shift lock when the unequip the tool?

Any help is appreciated!

1 Like

Anyone know how to do go about this?

1 Like

Does no one know how to do this?

1 Like

Not sure if it’s possible to force a key push of any type. You can however change what triggers whatever that push will do. Say you have a function the key push is directed towards. You could then send a trigger to that function yourself. if keypush == true or mytrigger == true then … to the push function.

Could you explain what you mean?

I edited the PlayerModule and made it so it locks the mouse if the tool has the attribute “ForceMouseLock” (boolean), i made a few changes and they were gonna be pretty annoying to list them all here, so if you want to you can read them, all the modules i edited are the BaseCamera and MouseLockController.

PlayerModule.rbxm (125.4 KB)

Everything you suggested is completely off-topic, I’m not asking for help on client input, I’m asking how I could replicate the shift lock while a player is holding a tool.

Does my post not help you?

and no, this is not impossible.

1 Like

Perhaps there’s a way through programming a solution? Like manipulating the camera? etc…

1 Like

There is a way, 100%. I see it in my friend’s game but I don’t know how. I know this is unhelpful but I’m just assuring you it is possible.

I didnt really understand what you mean?

Also, there’s a lot of code in there, half of which I don’t understand, I don’t want to be reliant on code I don’t know.

I gave you an edited version of the PlayerModule (which is already in your game, it is simply an edited version), after you insert it you can simply set an attribute on the tool called “ForceMouseLock” and it will force shift lock when that tool is equipped, like i said, i can’t list all the changes i made and i understand you may not want to rely on that code.

Please read BaseCamera and MouseLockController if you wish to know what i changed, all i edited were thoses two, the rest of the code is roblox’s default code.

I don’t know what code your talking about, there’s about 50 scripts in the player Module each containing 50 to 300 lines of code, It would be easier if you could paste here on the forums the code which you added or edited.

There is 819 lines of code.

There is 211 lines of code

Could you narrow it down for me please?

I’m sure there is somehow, … Maybe ask a different question, like what is the reason you’re trying to force the shift lock. What are you looking to accomplish here. There most likely is a workaround for it.

I don’t really know any other better way to explain what I want to do, most people are familiar with shift lock so I’m using that as an example.

I want to make for example when a player holds a gun (tool), then they would be snapped into the shift lock type thing, meaning, wherever their camera looks, that’s the way the player will face.


force shift lock tool

in toolbox. It gives you a folder with a tool and 3 scripts, tells you where to put them. i understand you want to know what it does, so read over the scripts

I also want the player’s mouse to be locked into the centre of the screen.

How would I do that?

Alright, like i said i made multiple changes but i will list here all the functions i edited:

  1. MouseLockController:OnMouseLockToggled()
  2. CameraModule:Update()
  3. added CameraModule:CheckForTool()

I edited the CameraModule not BaseCamera, sorry for the small mistake

Here’s a demo, hopefully it is what you wanted to achieve.

You must set ForceMouseLock attribute to true, as that’s how it knows what tools you want and don’t want to force the lock on.

1 Like

I misunderstood what you were doing.

1 Like