local function q(q,r,w)local B=q:FindFirstChild("\072\117\109\097\110\111\105\100")if B.RigType==Enum.HumanoidRigType.R15 then for r,w in pairs(r:GetChildren())do local B=q:FindFirstChild(w.Name)if B then(w:Clone()).Parent=q B.Name=""B:Destroy()end end buildRigFromAttachments(nil,q.HumanoidRootPart)else for r,w in pairs(w:GetChildren())do local B=getOldCharacterMesh(q,w)if B then B:Destroy()end w.Parent=q end end end local r=game:GetService("\065\115\115\101\116\083\101\114\118\105\099\101")local w=game:GetService("\073\110\115\101\114\116\083\101\114\118\105\099\101")function DressCharacter(B,E,v)local Z=r:GetAssetIdsForPackage(E)local x=B:FindFirstChild("\072\117\109\097\110\111\105\100")v=v or false for r,E in pairs(Z)do local Z=w:LoadAsset(E)for r,w in pairs(Z:GetChildren())do if w:IsA("\070\111\108\100\101\114")and w.Name=="\082\049\053"then q(B,w,nil)elseif w:IsA("\084\111\111\108")and v then x:EquipTool(w)elseif w:IsA("\065\099\099\101\115\115\111\114\121")or w:IsA("\072\097\116")then x:AddAccessory(w)end end Z:Destroy()end return true end return DressCharacter
-- Will apply a body part given the r15Folder and the r6Folder for that body part.
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)
			if oldPart then
				part:Clone().Parent = character
				oldPart.Name = ""
				oldPart:Destroy()
			end
		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(r6Folder:GetChildren()) do
			local oldCharacterMesh = getOldCharacterMesh(character, characterMesh)
			if oldCharacterMesh then
				oldCharacterMesh:Destroy()
			end
			characterMesh.Parent = character
		end
	end
end

local AssetService = game:GetService("AssetService")
local InsertService = game:GetService("InsertService")

function DressCharacter(character, packageId, allowTools)
	local PackageIds = AssetService:GetAssetIdsForPackage(packageId)
	local Humanoid = character:FindFirstChild("Humanoid")
	allowTools = (allowTools or false)

	for _, AssetId in pairs(PackageIds) do
		local Insert = InsertService:LoadAsset(AssetId)

		for _, Object in pairs(Insert:GetChildren()) do
			if Object:IsA("Folder") and Object.Name == "R15" then
				applyBodyPart(character, Object, nil)
			elseif Object:IsA("Tool") and allowTools then
				Humanoid:EquipTool(Object)
			elseif Object:IsA("Accessory") or Object:IsA("Hat") then
				Humanoid:AddAccessory(Object)
			end
		end

		Insert:Destroy()
	end

	return true
end

return DressCharacter
