Can you show the entirety of the code segment? It might benefit you to bind some sort of camera code to ContextActionService so that when the player moves the mouse it’ll execute some code… Following is a segment of code I used to accomplish the same goal:
function MovementClient:SetMouse(locked) --If locked == false, we can move the mouse around (Important for menus to work.)
if locked then
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
UserInputService.MouseIconEnabled = false
else
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
UserInputService.MouseIconEnabled = true
end
end
function MovementClient:CameraSetup(enabled)
if enabled then
workspace:WaitForChild("Camera")
MovementClient:SetMouse(true)
local angle_x = 0
local angle_y = 0
local cameraPos = Vector3.new(3.5,1.1,9) -- Vector3.new(2.8,1.1,9)
ContextActionService:BindAction("MouseCameraMovement", function(_,_,input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
angle_x = angle_x - input.Delta.x*0.4
angle_y = math.clamp(angle_y - input.Delta.y*0.4, -80, 80)
elseif input.KeyCode == Enum.KeyCode.Thumbstick2 then
angle_x = angle_x - input.Delta.X*0.4
angle_y = math.clamp(angle_y+input.Delta.Y*0.4, -80, 80)
end
end, false, Enum.UserInputType.MouseMovement, Enum.KeyCode.Thumbstick2)
--[[ContextActionService:BindAction("ControllerCameraMovement", function(_,_,input)
angle_x += -input.Delta.x * 360
angle_y += -input.Delta.y * 360
end, false, Enum.KeyCode.Thumbstick2)
]]
RunService:BindToRenderStep("CameraController", Enum.RenderPriority.Camera.Value +1, function()
if Character then
--print(angle_x, ", ", angle_y)
local startCFrame = CFrame.new(Character.HumanoidRootPart.CFrame.p) * CFrame.Angles(0, math.rad(angle_x), 0) * CFrame.Angles(math.rad(angle_y), 0, 0) --CFrame.Angles(0, math.rad(angle_x), 0) * CFrame.Angles(math.rad(angle_y), 0, 0)
local cameraCFrame = startCFrame + startCFrame:VectorToWorldSpace(Vector3.new(cameraPos.X, cameraPos.Y, cameraPos.Z))
local cameraFocus = startCFrame + startCFrame:VectorToWorldSpace(Vector3.new(cameraPos.X, cameraPos.Y, -100000))
workspace.CurrentCamera.CFrame = CFrame.new(cameraCFrame.p, cameraFocus.p)
if not WallRunning then
Character.HumanoidRootPart.CFrame = CFrame.new(Character.HumanoidRootPart.CFrame.p, Character.HumanoidRootPart.CFrame.p + Vector3.new(workspace.CurrentCamera.CFrame.LookVector.X, 0, workspace.CurrentCamera.CFrame.LookVector.Z))
end
end
end)
end
end
This code obviously includes some variables that you probably don’t need, such as wallrunning, but it features an over the shoulder camera angle. Modifying it slightly should yield the results you need. Make sure you only set MouseBehavior once though, not on every frame.