Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- stolen from here <https://devforum.roblox.com/t/using-getassetidsforpackage-not-working/210592/13?u=call23re2> but fixed
- local as = game:GetService('AssetService')
- local is = game:GetService('InsertService')
- local marketplaceService = game:GetService('MarketplaceService')
- local assetTypeDic = {
- [27] = Enum.AssetType.Torso,
- [28] = Enum.AssetType.RightArm,
- [29] = Enum.AssetType.LeftArm,
- [30] = Enum.AssetType.RightLeg,
- [31] = Enum.AssetType.LeftLeg,
- [17] = Enum.AssetType.Head,
- [41] = Enum.AssetType.HairAccessory,
- [42] = Enum.AssetType.FaceAccessory,
- [43] = Enum.AssetType.NeckAccessory,
- [44] = Enum.AssetType.ShoulderAccessory,
- [45] = Enum.AssetType.FrontAccessory,
- [46] = Enum.AssetType.BackAccessory,
- [47] = Enum.AssetType.WaistAccessory,
- [57] = Enum.AssetType.EarAccessory,
- [58] = Enum.AssetType.EyeAccessory
- }
- 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
- local 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
- local function applyBodyPart(character, r15Folder, r6Folder)
- 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
- buildRigFromAttachments(nil, character.HumanoidRootPart)
- else
- for _, characterMesh in pairs(r6Folder:GetChildren()) do
- local oldCharacterMesh = getOldCharacterMesh(character, characterMesh)
- if oldCharacterMesh then
- oldCharacterMesh:Destroy()
- end
- characterMesh.Parent = character
- end
- end
- end
- local function getAssetIds(bundleId)
- local details = as:GetBundleDetailsAsync(bundleId)
- local ids = {}
- for i, detail in pairs(details) do
- if type(detail) == "table" then
- for _, d in pairs(detail) do
- if type(d) == "table" then
- for _, a in pairs(d) do
- if type(a) == "number" then
- local info = marketplaceService:GetProductInfo(a)
- if assetTypeDic[info.AssetTypeId] then
- table.insert(ids, a)
- end
- end
- end
- end
- end
- end
- end
- return ids
- end
- function ImportPackage(packageId, char)
- local humanoid = char:FindFirstChild("Humanoid")
- local rigType = humanoid.RigType
- if packageId ~= 1 then
- local ids = getAssetIds(packageId)
- for _, assetId in pairs(ids) do
- local asset = is:LoadAsset(assetId)
- if rigType == Enum.HumanoidRigType.R6 then
- if asset:FindFirstChild("R6") then
- applyBodyPart(char, nil, asset.R6)
- else
- if asset:FindFirstChildOfClass("Accessory") then
- local accessory = asset:FindFirstChildOfClass("Accessory")
- accessory.Parent = char
- humanoid:AddAccessory(accessory)
- elseif asset:FindFirstChildOfClass("Tool") then
- asset.Parent = char
- end
- end
- else
- if asset:FindFirstChild("R15Fixed") then
- local folder = asset:FindFirstChild("R15Fixed")
- applyBodyPart(char, folder, nil)
- elseif asset:FindFirstChild("R15Anim") then
- asset:FindFirstChild("R15Anim").Parent = char
- elseif asset:FindFirstChild("Mesh") then
- char.Head:FindFirstChildOfClass("SpecialMesh"):Destroy()
- asset:FindFirstChild("Mesh").Parent = char:WaitForChild("Head")
- elseif asset:FindFirstChild("face") then
- char.Head:FindFirstChildOfClass("Decal"):Destroy()
- asset:FindFirstChild("face").Parent = char:WaitForChild("Head")
- else
- if asset:FindFirstChildOfClass("Accessory") then
- local a = asset:FindFirstChildOfClass("Accessory")
- a.Parent = char
- humanoid:AddAccessory(a)
- elseif asset:FindFirstChildOfClass("Tool") then
- asset:FindFirstChildOfClass("Tool").Parent = char
- elseif asset:FindFirstChildOfClass("Decal") then
- char.Head:FindFirstChildOfClass("Decal"):Destroy()
- asset:FindFirstChildOfClass("Decal").Parent = char.Head
- end
- end
- end
- end
- end
- humanoid.HipHeight = 1.35
- end
- ImportPackage(451, workspace.Dummy) -- bundle id, path to character
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement