So, I want to make a gun with shoulder camera, and I want for the player to go into mouselock when they equip it, and leave it when they unequip, however, I’m not sure how to do this. Can someone help me, please?
There isn’t really a way to enable shiftlock using scripts, but you could make your own shiftlock:
Here’s a simple script that I’ve made:
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local rootPart = char:WaitForChild("HumanoidRootPart")
local humanoid = char:WaitForChild("Humanoid")
local tool = script.Parent
local event
function enableShiftlock()
--lock mouse to center
game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
local rootPos = rootPart.Position
local camLook = workspace.CurrentCamera.CFrame.LookVector
--set rotation to the camera's direction
rootPart.CFrame = CFrame.new(rootPos,rootPos+Vector3.new(camLook.X,0,camLook.Z))
end
tool.Equipped:Connect(function()
--disable auto rotate to prevent bugs
humanoid.AutoRotate = false
--on every frame update rotation
event = game:GetService("RunService").RenderStepped:Connect(enableShiftlock)
end)
tool.Unequipped:Connect(function()
--enable auto rotate since tool is unequipped
humanoid.AutoRotate = true
if event then
--stop the loop
event:Disconnect()
end
end)
Basically what this does is, set’s the rotation of the character to the angle of the camera’s X and Y.
I hope this helped!
Thanks, I’ll try and see if this works!
Hang on, does the “Event” variable need a value? And does it need to be in a local or server script?
Well the event variable is just to store the RenderStepped so you can end it later, because if you don’t disconnect it, It will just keep running the shiftlock code. And It would be in a localscript, inside the tool.
Tried it yesterday, forgot to turn off “RequiresHandle”. Did that today and it worked! Thanks!
It doesn’t put the camera over the shoulder. It just locks the mouse and makes the character turn with it.