Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function buildJoint(parentAttachment, partForJointAttachment)
- local jointName = parentAttachment.Name:gsub("RigAttachment", "")
- local motor = partForJointAttachment.Parent:FindFirstChild(jointName)
- if not motor then
- motor = Instance.new("Motor6D")
- end
- motor.Name = jointName
- motor.Part0 = parentAttachment.Parent
- motor.Part1 = partForJointAttachment.Parent
- motor.C0 = parentAttachment.CFrame
- motor.C1 = partForJointAttachment.CFrame
- motor.Parent = partForJointAttachment.Parent
- end
- function buildRigFromAttachments(last, part)
- for _, attachment in pairs(part:GetChildren()) do
- if attachment:IsA("Attachment") and string.find(attachment.Name, "RigAttachment") then
- for _, sibling in pairs(part.Parent:GetChildren()) do
- if sibling ~= part and sibling ~= last then
- local matchingAttachment = sibling:FindFirstChild(attachment.Name)
- if matchingAttachment then
- buildJoint(attachment, matchingAttachment)
- buildRigFromAttachments(part, matchingAttachment.Parent)
- end
- end
- end
- end
- end
- end
- local function getOldCharacterMesh(character, newCharacterMesh)
- for _, obj in pairs(character:GetChildren()) do
- if obj:IsA("CharacterMesh") and obj.BodyPart == newCharacterMesh.BodyPart then
- return obj
- end
- end
- return nil
- end
- function applyBodyPart(character, r15Folder)
- local humanoid = character:FindFirstChild("Humanoid")
- if humanoid.RigType == Enum.HumanoidRigType.R15 then
- for _, part in pairs(r15Folder:GetChildren()) do
- local oldPart = character:FindFirstChild(part.Name)
- part:Clone().Parent = character
- oldPart.Name = ""
- oldPart:Destroy()
- end
- -- Rebuild the rig
- -- Note: if applying many body parts at once it is more efficient to call this after applying them all
- buildRigFromAttachments(nil, character.HumanoidRootPart)
- else
- for _, characterMesh in pairs(r15Folder:GetChildren()) do
- local oldCharacterMesh = getOldCharacterMesh(character, characterMesh)
- if oldCharacterMesh then
- oldCharacterMesh:Destroy()
- end
- characterMesh.Parent = character
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement