ViewModel CFrame Problem

Hey! I’m having trouble getting my view model arm to point at a specific position. I have never really messed around with CFrames too much so I am hoping somebody could point me in the right direction!

My current code consist of imported code that accomplishes this exact thing but for R6 models rather than a ViewModel:

local CN,CA =,CFrame.Angles
local an = math.asin

local armOffset = ViewModel.HumanoidRootPart.CFrame:Inverse() * ViewModel["RightArm"].CFrame

armWeld ="Weld")
armWeld.Part0 =  ViewModel.HumanoidRootPart
armWeld.Part1 =  ViewModel["RightArm"]
armWeld.Parent =  ViewModel.HumanoidRootPart
RenderConnection = RunService.RenderStepped:Connect(function(deltaTime)
	local cframe = CN( ViewModel.HumanoidRootPart.Position, workspace.Part.Position) * CA(math.pi/2, 0, 0)
	armWeld.C0 = armOffset * ViewModel.HumanoidRootPart.CFrame:toObjectSpace(cframe) * CN(0,0,-0.5)

I thought that since the ViewModel rig is pretty similar to the r6 rig it would work correctly but it had a few odd problems:

The goal of this is so the arm points in the correct orientation to the grey part’s position^

I’m not too familiar with this type of work~

The rig of the view model looks like this:

Once again if you could help or point me in the right direction it is highly appreciated!

If you need anymore information, examples, feel free to ask

1 Like

It looks like you’re trying to make the arm of the view model point at a specific position in the world, represented by the grey part. To do this, you can use the CFrame.LookAt function, which creates a transformation that rotates a frame so that its z axis points towards a specific point in space.

1 Like

I’ve tried a few things but nothing seemed to work, could you possibly provide an example of how CFrame.LookAt would look in my code?