Hello. I am trying to force-activate/deactivate shift lock in my game.
However, when I looked it up in the dev forums, none of the solutions helped me. It seemed to work for others, but not for me. Does anyone have a simple solution for this?
Hello. I am trying to force-activate/deactivate shift lock in my game.
However, when I looked it up in the dev forums, none of the solutions helped me. It seemed to work for others, but not for me. Does anyone have a simple solution for this?
I was definitely struggling with this too a couple days ago. I couldn’t figure out a way to “force” shift lock, but I was able to make the player face the direction of the camera. Is that what you want, or does it need to be shift lock?
Making the player face the camera is not exactly difficult. However, I’m sure there is a way to modify some core scripts to open and close shift-lock. Does your way of making the mouse face the camera involve using renderstep?
Yeah my method does include RenderStep. The following code doesn’t set it exactly to shift lock, but it locks the mouse in the center of the screen. If they need to use a GUI they can hold ALT. You could combine this with a RenderStep to make them face the camera direction. There is probably a better method though.
local userInputService = game:GetService("UserInputService")
game:GetService("RunService").RenderStepped:Connect(function() -- you could replace this with InputBegan and InputEnded if you want
if userInputService:IsKeyDown(Enum.KeyCode.LeftAlt) == true or userInputService:IsKeyDown(Enum.KeyCode.RightAlt) == true then
userInputService.MouseBehavior = Enum.MouseBehavior.Default
userInputService.MouseIconEnabled = true
else
userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
userInputService.MouseIconEnabled = true --change to false if you want invisible mouse
end
end)