Force shiftlock when tool is equipped

I am working on a combat system, and everything works fine. However i could make my combat more dynamic and skill-based, if i was able to shiftlock player when he equips the sword. I dont want shiftlock to be enabled always, as it is not just a combat game, but when equipping sword shiftlock would be perfect.

I am good at scripting so not asking for a whole script, i just couldnt find any information on how to force shiftlock at certain point of the game, and then disable it again

2 Likes

You could try this to mimic shift lock behavior:

local script BTW

game:GetService"UserInputService".MouseBehavior = Enum.MouseBehavior.LockCenter

Also to actually toggle between actual shift lock I’m pretty sure this is what I used (on mobile rn)

game.Workspace.CurrentCamera:SetIsMouseLocked(true) — True or false
3 Likes

Looked at MouseBehavior at dev hub, looks like it will work even better than shiftlocking. Marking as solution for now, ill try this tomorrow and tell you how it went. Thank you!!!)

2 Likes

None of this worked.

MouseBehavior.LockCenter just changes mouse position to the center, but then i can move it again freely, + the camera doesnt rotate with mouse.

SetIsMouseLocked resulted in an error

is not a valid member of Workspace.Camera

2 Likes

Roblox, for some reason, doesn’t have the tools for developers to force a player into shift lock camera. However, using some trickery, a free module has been released that allows you to do just that.

I actually found a very optimized and perfectly working solution for this. I stopped using it because I ended up making my game first person (because looks a lot cooler that way), but I can share here the shiftlock code if you’re interested

1 Like

Yeah, that would be cool if you would like to do that!

:frowning: he never shared the code RAAAAH