Making an NPC rig's right hand point at a player

Hello everyone! So, i’m having trouble trying to make an NPC use it’s right arm to point at the closest player to it. I have tried using Motor6Ds to achieve this, but i can’t seem to even get the arm to budge at all. Here is what i have tried doing thus far: (both did not make the arm move even a bit)

Attempt 1: (Trying to do a simple “Point at this part”)

game["Run Service"].Stepped:Connect(function()
if pointing then
	print("Pointing")
	humanoid.Parent.Torso["Right Shoulder"].Transform = CFrame.new(humanoid.Parent["Right Arm"].Position, target.Character.PrimaryPart.Position)
end end)

Attempt 2: (Using a modified version of this guide)

game["Run Service"].Stepped:Connect(function()
if pointing then
	print("Pointing")
	local RotationOffset = (humanoid.Parent["Right Arm"].CFrame-humanoid.Parent["Right Arm"].CFrame.p):inverse()
	local RealPos = -(humanoid.Parent["Right Arm"].CFrame.p - target.Character.PrimaryPart.Position).unit * 5000
	humanoid.Parent.Torso["Right Shoulder"].Transform = RotationOffset * CFrame.new(Vector3.new(0, 0, 0), RealPos)
end end)

I should also note, there is a part welded to the right arm, but the part is not anchored, can’t collide with anything, and is mass-less. This is also my first time messing with Motor6Ds besides doing animations.
As always, any help will be greatly appreciated! :smiley:

1 Like

Here is something I did for a flashlight it uses Mouse.Hit but you can change that to the cframe.new(Vector3,Player)

local jointPosition = ArmMotor6D.Part0.CFrame:toWorldSpace(CFrame.new(0.9,0.25,0.25))
local cframe = CFrame.new(jointPosition.p, PlayerTorsoPositionOrWhatever) * CFrame.Angles(math.pi/2, 0, 0) * CFrame.new(0, -1, 0)
ArmMotor6D.C0 = ArmMotor6D.Part0.CFrame:toObjectSpace(cframe)

This should work for the most part.

5 Likes

Thanks a bunch! It works great! I modified it a bit so it works with what i’m doing. So does Motor6D.Transform not work? Or am was i using it wrong?

3 Likes