I have a custom shiftlock script that I made, and whenever MouseBehavior is set to default I cant rotate my camera with M2/RMB. Does anyone know how to fix this?
Script:
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")
local hum = character:WaitForChild("Humanoid")
local runService = game:GetService("RunService")
local uis = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local locked = false
uis.InputBegan:Connect(function(input,GPE)
if not GPE and input.KeyCode == Enum.KeyCode.LeftControl then
locked = not locked
end
end)
local lerpMoveDirection = Vector3.new()
runService.RenderStepped:Connect(function()
lerpMoveDirection = lerpMoveDirection:Lerp(hum.MoveDirection,0.2)
print(lerpMoveDirection)
if locked == true then
uis.MouseBehavior = Enum.MouseBehavior.LockCenter
local lookVec = camera.CFrame.lookVector
local angle = -math.atan2(lookVec.Z, lookVec.X) + math.rad(270)
root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0, angle, 0)
else
uis.MouseBehavior = Enum.MouseBehavior.Default
if hum.MoveDirection.Magnitude ~= 0 then
root.CFrame = CFrame.new(root.Position, root.Position+lerpMoveDirection)
end
end
end)