local O=require(script.Parent.t)local z=O.instance("\065\116\116\097\099\104\109\101\110\116")local b={}function b.WeldAttachments(X,b,i)assert((O.tuple(z,z))(b,i))local y=Instance.new("\087\101\108\100")y.Part0=b.Parent y.Part1=i.Parent y.C0=b.CFrame y.C1=i.CFrame y.Parent=b.Parent return y end local i=O.tuple(O.instance("\077\111\100\101\108"),O.string)function b.FindFirstMatchingAttachment(b,O,z)assert(i(O,z))for O,b in pairs(O:GetDescendants())do if b:IsA("\065\116\116\097\099\104\109\101\110\116")and b.Name==z then return b end end end local X=O.tuple(O.instance("\077\111\100\101\108"),O.instanceIsA("\065\099\099\111\117\116\114\101\109\101\110\116"),O.optional(O.string))function b.WeldAccoutrement(i,O,z,b)assert(X(O,z,b))b=b or"\072\097\110\100\108\101"local y=z:FindFirstChild(b)if y then local b=y.FindFirstChildOfClass("\065\116\116\097\099\104\109\101\110\116")if b then local X=i:FindFirstMatchingAttachment(O,b.Name)if X then i:WeldAttachments(b,X)z.Parent=O return z else error("\067\111\117\108\100 \110\111\116 \102\105\110\100 \109\097\116\099\104\105\110\103 \096"..(tostring(b.Name).."\096 \097\116\116\097\099\104\109\101\110\116 \105\110 \099\104\097\114\097\099\116\101\114\033"))end else error("\067\111\117\108\100 \110\111\116 \102\105\110\100 \065\116\116\097\099\104\109\101\110\116 \105\110 \104\097\110\100\108\101 \096"..(tostring(y).."\096"))end else error("\078\111 \104\097\110\100\108\101 \100\101\116\101\099\116\101\100\033")end end b.WeldAccessory=b.WeldAccoutrement return b
local t = require(script.Parent.t)
local tattachment = t.instance("Attachment")

local Welds = {}

function Welds:WeldAttachments(attach1, attach2)
	assert(t.tuple(tattachment, tattachment)(attach1, attach2))

	local weld = Instance.new("Weld")
	weld.Part0 = attach1.Parent
	weld.Part1 = attach2.Parent
	weld.C0 = attach1.CFrame
	weld.C1 = attach2.CFrame
	weld.Parent = attach1.Parent
	return weld
end

local ARGT_FindFirstMatchingAttachment = t.tuple(t.instance("Model"), t.string)
function Welds:FindFirstMatchingAttachment(model, name)
	assert(ARGT_FindFirstMatchingAttachment(model, name))
	for _, child in pairs(model:GetDescendants()) do
		if child:IsA("Attachment") and child.Name == name then
			return child
		end
	end
end

local ARGT_WeldAccoutrement = t.tuple(t.instance("Model"), t.instanceIsA("Accoutrement"), t.optional(t.string))
function Welds:WeldAccoutrement(character, accessory, handleName)
	assert(ARGT_WeldAccoutrement(character, accessory, handleName))
	handleName = handleName or "Handle"

	local handle = accessory:FindFirstChild(handleName)
	if handle then
		local accoutrementAttachment = handle.FindFirstChildOfClass("Attachment")
		if accoutrementAttachment then
			local characterAttachment = self:FindFirstMatchingAttachment(character, accoutrementAttachment.Name)
			if characterAttachment then
				self:WeldAttachments(accoutrementAttachment, characterAttachment)
				accessory.Parent = character
				return accessory
			else
				error("Could not find matching `" .. tostring(accoutrementAttachment.Name) .. "` attachment in character!")
			end
		else
			error("Could not find Attachment in handle `" .. tostring(handle) .. "`")
		end
	else
		error("No handle detected!")
	end
end
Welds.WeldAccessory = Welds.WeldAccoutrement

return Welds
