When I rotate my character in any direction, it’ll weld incorrectly. To be specific, it’ll weld on the back of the leg because the script doesn’t know how to factor in offsets or whatever CFrame magic will make this problem go away.
return function(Character, Object)
if Character and Object then
local RightUpperLeg = Character:WaitForChild("RightUpperLeg")
local PrimaryPart = Object.PrimaryPart
PrimaryPart.Position = RightUpperLeg.Position
local Weld = Instance.new("Weld")
Weld.C0 = RightUpperLeg.CFrame:ToObjectSpace(PrimaryPart.CFrame + Vector3.new((RightUpperLeg.Size.X / 2) + 0.02, 0, -0.2))
Weld.Part0 = RightUpperLeg
Weld.Part1 = PrimaryPart
Weld.Parent = PrimaryPart
Object.Parent = Character
end
end
Any help is appreciated. I can’t use the accessory instance because I’m trying to make the leg object fit on any character regardless of their size/bundle. (If I use accessory, certain packages like the woman package will make the leg object float in the air.)
WeldConstraints are much more easier and simpler to use. If the thing your welding is a model, make sure to weld all it’s descendants to the model’s primary part. That way when you weld the primary part to the leg, everything else follows.
CFrame is relative to the part, while Position is not. This is why your script only works in certain directions. In CFrame, for example, the X axis is always to the right and left of the character. In position there is a fixed X axis.
So you can put a leg in, add an attachment to the leg and move it to where your items root should be and copy the relative position. It’s Position is defined in the parts object space which is easy enough to replicate.
Well certainly you can need scaling along the relevant axis if you have varied bodies.
The main aspect is visualizing the position and getting a number from it relative to your body part. It makes a great start.
If you click on your object in studio, make sure the parts basically all face the same direction. If the front view of the object is along the Z axis, but the other object’s front direction is along the X axis it won’t work properly.