How to properly align knife to hand?

I’m basically cloning a part and sticking it to a player’s hand (so, I’m not using a tool and using :EquipTool(tool) on the player). However, the knife isn’t positioning as how I would like it to.

Here is how the knife looks like in-game:

Here is how I would want the knife to look like:
help2

Here is my code:

local knifeClone = game.ServerStorage.Items.Knife:Clone();
knifeClone.Parent = workspace;

local currentPlayerRShoulderJoint = player.Character["RightUpperArm"]["RightShoulder"];

-- Move arm up 45 degrees
if currentPlayerRShoulderJoint then
    currentPlayerRShoulderJoint.C0 = currentPlayerRShoulderJoint.C0 * CFrame.Angles(math.rad(45), 0, 0);
end

local weld = Instance.new("Weld", knifeClone);
weld.Part0 = knifeClone;
weld.Part1 = player.Character["RightHand"];
weld.C0 = knifeClone.CFrame;
weld.C1 = player.Character["RightHand"].CFrame;

I’ve tried manipulating the welds where the knife meets the player’s hand, but am unable to rotate the knife.

You need to change the CFrame angle of the weld to something like CFrame.Angles(0, math.rad(90), 0)
Try looking here: CFrames | Roblox Creator Documentation

Gotcha. So I did something like this:

weld.C0 = knifeClone.CFrame;
weld.C0 = weld.C0 * CFrame.Angles(0, math.rad(45), 0);

It’s still in the workspace, but has completely disappeared. Am I manipulating the right weld?

What would weld.C1 be then?

play around with the offset and angle variables

local knifeClone = game.ServerStorage.Items.Knife:Clone();
knifeClone.Parent = workspace;

local currentPlayerRShoulderJoint = player.Character["RightUpperArm"]["RightShoulder"];

-- Move arm up 45 degrees
if currentPlayerRShoulderJoint then
    currentPlayerRShoulderJoint.C0 = currentPlayerRShoulderJoint.C0 * CFrame.Angles(math.rad(45), 0, 0);
end

local knifeOffset = CFrame.new(0, 1, 0)
local knifeAngle = CFrame.Angles(0, math.pi/2, 0)

local weld = Instance.new("Weld", knifeClone)
weld.Part0 = player.Character["RightHand"]
weld.Part1 = knifeClone
weld.C0 = player.Character['RightHand'].CFrame * player.Character['RightHand'].CFrame:ToObjectSpace(knifeOffset) * knifeAngle
1 Like

If you’re attaching something to a player, use Rigid Constraints. First, test your game and switch to the server. Manually add a rigid constraint from your character to the knife. If it’s not positioned correctly, change the orientation of the [Rigid Constraint].Attachment0 or [Rigid Constraint].Attachment1 (it’s either one of these two) until you find a suitable position for the knife. Lastly, script the knife to your desired position.

1 Like

While you could accomplish this by messing with the C0 values, I think the easier way of doing this (at least for me) would to just use this plugin on a dummy with the knife, use a motor6d (if you wanna animate it) or use a weld (if you dont want to animate it), set it to how you want, then just use the generated motor/weld instead of creating a new one with Instance.new().

Here’s the free version of the plugin I was talking about. (RigEdit Lite - Roblox)

1 Like

Great solution.
If you ever want to find an item in the workspace, just select it in the explorer window, then select the Move tool. This will give the blue, green and red dragger tools around the item so you can see where it is.