Last active
November 15, 2021 23:14
-
-
Save FirstVertex/ad6d49b70176850c94ac0589a5d45bc4 to your computer and use it in GitHub Desktop.
Roblox Accessories with WeldConstraints have problems. This fixes the shifting that happens when Accessories with welded parts are parented to the Character.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addAccessoryWithWeldConstraints(humanoid: Humanoid, accessory: Accessory) { | |
const handle = accessory.FindFirstChild('Handle') as BasePart; | |
if (!handle) { | |
return; | |
} | |
humanoid.AddAccessory(accessory); | |
const os = handle.FindFirstChild('OriginalSize') as Vector3Value; | |
if (os) { | |
const sizeChange = handle.Size.div(os.Value); | |
handle.GetDescendants().forEach(desc => { | |
if (desc.IsA('WeldConstraint')) { | |
const { Part0, Part1 } = desc; | |
if (Part0 && Part1) { | |
const weldCF = Part1.CFrame.ToObjectSpace(Part0.CFrame); | |
const orientation = weldCF.sub(weldCF.Position); | |
const weld = new Instance('Weld', desc.Parent); | |
weld.Part0 = Part0; | |
weld.Part1 = Part1; | |
weld.C1 = new CFrame(weldCF.Position.mul(sizeChange)).mul(orientation); | |
desc.Destroy(); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Roblox Dev forum post about it is here
Conversion to Lua is here