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:
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)```