---------------------------------------------------------------------------------------------------------------------------
-- Functions
---------------------------------------------------------------------------------------------------------------------------


local function Weld(X, Y)
	local CJ = CFrame.new(X.Position)
	local C0 = X.CFrame:inverse()*CJ
	local C1 = Y.CFrame:inverse()*CJ
	
	local W = Create("Weld"){
		Name = "Weld",
		Parent = X,
		Part0 = X,
		Part1 = Y,
		C0 = C0,
		C1 = C1
	}
end

local function WeldObjects(parent)
	for i, obj in pairs(parent:GetChildren()) do
		if obj:IsA("BasePart") then
			Weld(Handle, obj)
			obj.Anchored = false
			-- print("[Weld] Objects have been welded!")
		end
	end
end

Tool.Equipped:connect(function()
	WeldObjects(Tool)
end)

Tool.Unequipped:connect(function()
	WeldObjects(Tool)
end)
