Camera CFrame not working correctly

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want a gun that follow the camera

  2. What is the issue? I am trying to make a gun script and the gun moves with the camera but it doesn’t move correctly. https://gyazo.com/bdfb15e5adff1f0dbe5bf7da19af454e

  3. What solutions have you tried so far? I tried using a bunch of different formulas but I cant get it to work.

function TweenRotation()
	local Part1 = Panel.PrimaryPart
	local TweenService = game:GetService("TweenService")

	local x, y, z = Camera.CFrame:toEulerAnglesXYZ()

	local PanelSwingInfo = TweenInfo.new(0.1) -- Let's use all defaults here

	local PanelSwingTween = TweenService:Create(PanelRoot, PanelSwingInfo, {
	CFrame = Camera.CFrame
	
	})

	PanelSwingTween:Play()
end


game:GetService("RunService").RenderStepped:Connect(function()
	Panel:SetPrimaryPartCFrame(CFrame.new(Camera.CFrame.Position, PanelRoot.Orientation))
	--PanelRoot.CFrame = Camera.CFrame:ToWorldSpace()
	--PanelRoot.Position = Camera.CFrame.Position
	--PanelRoot.Orientation = Camera.CFrame.LookVector
	if num == 4 then
		TweenRotation()
		num = 0
	end
	num = num + 1
end)

If you run the Panel:Set… on its own (without the RenderStep) does that work?

Yes if i just run it once it goes right up to my camera

function TweenRotation(FunctCamera)
	local Part1 = Panel.PrimaryPart
	local TweenService = game:GetService("TweenService")

	local x, y, z = FunctCamera.CFrame:toEulerAnglesXYZ()

	local PanelSwingInfo = TweenInfo.new(0.1) -- Let's use all defaults here
	local Camera = game.Workspace.CurrentCamera
	local PanelSwingTween = TweenService:Create(PanelRoot, PanelSwingInfo, {
		--CFrame = CFrame.Angles(x, y, z)
		--CFrame = CFrame.new(PanelRoot.Position) * CFrame.Angles(x, y, z)
	
		Orientation = FunctCamera.CFrame.LookVector
	})

	PanelSwingTween:Play()
end

	
	game:GetService("RunService").RenderStepped:Connect(function()
	local Camera = game.Workspace.CurrentCamera
	Panel:SetPrimaryPartCFrame(CFrame.new(Camera.CFrame.Position, PanelRoot.Orientation))
	
	if num == 4 then
		TweenRotation(Camera)
		num = 0
	end
	num = num + 1
end)

I changed it to this but with look vector it just spins around.