Make this custom third camera (shoulder) gamepad compatible

Hello people! I’ve recently got an xbox controller and I wanted to try it with this script. The script works well with the mouse, but it doesn’t with a controller. This is the script

local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local camera = workspace.CurrentCamera
local player = Players.LocalPlayer

local cameraOffset = Vector3.new(2,2,8)

player.CharacterAdded:Connect(function(character)
	local humanoid = character:WaitForChild("Humanoid")
	local rootPart = character:WaitForChild("HumanoidRootPart")
	
	local cameraAngleX = 0
	local cameraAngleY = 0
	
	humanoid.AutoRotate = false
	
	local function playerInput(actionName, inputState, inputObject)
		if inputState == Enum.UserInputState.Change then
			cameraAngleX -= inputObject.Delta.X
			cameraAngleY = math.clamp(cameraAngleY - inputObject.Delta.Y * 0.4, -75, 75)
		end
	end
	ContextActionService:BindAction("PlayerInput", playerInput, false, Enum.UserInputType.Gamepad1, Enum.UserInputType.MouseMovement)
	
	RunService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function()
		local startCFrame = CFrame.new(rootPart.CFrame.Position) * CFrame.Angles(0, math.rad(cameraAngleX), 0) * CFrame.Angles(math.rad(cameraAngleY), 0, 0)
		local cameraCFrame = startCFrame:PointToWorldSpace(cameraOffset)
		local cameraFocus = startCFrame:PointToWorldSpace(Vector3.new(cameraOffset.X, cameraOffset.Y, -100000))
		
		camera.CFrame = CFrame.lookAt(cameraCFrame, cameraFocus)
		
		local lookingFrame = CFrame.lookAt(rootPart.Position, camera.CFrame:PointToWorldSpace(Vector3.new(0,0, -10000)))
		
		rootPart.CFrame = CFrame.fromMatrix(rootPart.Position, lookingFrame.XVector, rootPart.CFrame.YVector)
		
	end)
	
end)

local function focusControl(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		camera.CameraType = Enum.CameraType.Scriptable
		UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
		UserInputService.MouseIconEnabled = false
	end
end

ContextActionService:BindAction("FocusControl", focusControl, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch, Enum.UserInputType.Focus, Enum.UserInputType.Gamepad1)

If someone can help me I would be grateful. :smiley: