How do I weld two parts while keeping their relative position and orientation?

I have a handgun holster and it has its own CFrame which is relative to the dummy’s HumanoidRootPart, and I want to weld it to a player’s HumanoidRootPart while keeping the same relative position and orientation. How do I do that? I tried the following but I got odd results.

function module:Weld(part0: BasePart, part1: BasePart, inverse0: CFrame, inverse1: CFrame): Weld
	local weld = Instance.new("Weld")
	weld.Part0 = part0
	weld.Part1 = part1
	if inverse0 and inverse1 then
		weld.C0 = inverse0:Inverse()
		weld.C1 = inverse1:Inverse()
	else
		weld.C0 = part0.CFrame:Inverse()
		weld.C1 = part1.CFrame:Inverse()
	end
	weld.Parent = part1
	return weld
end
local weld = Util:Weld(character:FindFirstChild("Torso"), root,
	character.PrimaryPart.CFrame,
	gear:FindFirstChild("CFrameInfo").Value:ToObjectSpace(character.PrimaryPart.CFrame)
)

Use a WeldConstraint | Roblox Creator Documentation and don’t bother with C0 and C1 at all.

It will center the handgun holster to the humanoidrootpart instead of keeping its relative cframe resulting in the handgun holster being placed inside of the player’s torso which is not what I want to achieve.

Really the position thing is doubtful for me, but if you weld it with something, use weld.C0 = CFrame (10, 0, 0)

The orientation is put after putting the weld, for example:

local part = Instance.new("Part")
part.Parent = Workspace

local Weld = Instance.new("Weld")
Weld.Part0 = (NameTheObject)
Weld.Part1 = part
Weld.Parent = part
Weld.C0 = CFrame(19, 0, 0)

part.Orientation = Vector3.new(10, 20, 30)

I have no idea what you mean but if you insist on using a Weld instead of a WeldConstraint you can do

weld.C0 = part0.CFrame:Inverse() * part1.CFrame

I want to place the taser holster in this spot but on the player’s character programmatically.

Okay so, what’s your question exactly?

Set the C0 of the weld to whatever you want it to be.

Yeah but how? I need to know the right CFrame value so I can use it.

You can get the transform from the root to the holster like

local offset = root.CFrame:Inverse() * holster.CFrame

Then you can use that as the C0 of the weld later.

local offset = character:FindFirstChild("Torso").CFrame:Inverse() * holster.CFrame
local weld = Instance.new("Weld")
weld.Part0 = character:FindFirstChild("Torso")
weld.Part1 = holster
weld.C0 = offset

So what now? I don’t know what to do with the offset now
image

I mean that’s it. Does that not work?

I’m assuming the holster is already placed in the right position before you start welding?

Yes it doesn’t work, its completely off.

1 Like