Making tool point to mouse script help

Hi. I have a script that is meant to make the gun point smoothly towards the players mouse but it doesn’t work. This happens:
image

I also get the error “argument 3 missing or nil”

local character = player.Character
local mouse = player:GetMouse()

local armOffset = character.UpperTorso.CFrame:Inverse() * character.RightUpperArm.CFrame

local armWeld = Instance.new("Weld")
armWeld.Part0 = character.UpperTorso
armWeld.Part1 = character.RightUpperArm
armWeld.Parent = character

game:GetService("RunService").RenderStepped:Connect(function()
	local cframe = CFrame.new(character.UpperTorso.Position, mouse.Hit.Position) * CFrame.Angles(math.pi/2)
	local armc = armOffset * character.UpperTorso.CFrame:ToObjectSpace(cframe)
	local x,y,z = armc:ToOrientation()
	y = math.clamp(y,-45,45)
	armWeld.C0 = CFrame.new(armc.Position) * CFrame.Angles(math.rad(x),math.rad(y),math.rad(z))
end)```

The goal is to make the arm point to the players mouse





The problem is the line:
```local cframe = CFrame.new(character.UpperTorso.Position, mouse.Hit.Position) * CFrame.Angles(math.pi/2)

Your mouse.Hit.Position is nil.
From the docs:

The Hit property contains a RaycastResult if the mouse is over a BasePart; otherwise, it is nil.

Maybe you want to use ```mouse.Hit.p``` instead?