Hello, I am trying to made a custom shiftlock.
My code so far works, the camera offsets when I click shift but the mouse doesnt go to the middle like it does on the normal shiftlock.
This is my code so far
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local human = player.Character.Humanoid
local hrp = player.Character.HumanoidRootPart
local currentCamera = workspace.CurrentCamera
local mouse = player:GetMouse()
local shiftLock = false
local connection
--------------------------------------------------------------------------------------------------------------------------
UserInputService.InputBegan:Connect(function(input, gameEvent)
if not gameEvent then
if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
if not shiftLock then
shiftLock = true
else
connection:Disconnect()
shiftLock = false
human.AutoRotate = true
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
end
if shiftLock then
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
human.AutoRotate = false
connection = RunService.RenderStepped:Connect(function(dt)
local x,y,z = currentCamera.CFrame:ToOrientation()
hrp.CFrame = CFrame.new(hrp.Position) * CFrame.Angles(0, y, 0)
currentCamera.CFrame = currentCamera.CFrame * CFrame.new(3,3,0)
end)
end
end
end
end)
This line " UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition" makes me able to scroll the screen without holding down right click or shiftlock but the mouse doesnt go to the middle, how can I change it?