local function M(D,K)for K,W in K do if type(K)=="\110\117\109\098\101\114"and typeof(W)=="\073\110\115\116\097\110\099\101"then W.Parent=D continue end if type(W)=="\116\097\098\108\101"then M(D,W)continue end if typeof(D[K])=="\082\066\088\083\099\114\105\112\116\083\105\103\110\097\108"then D[K]:Connect(W)continue end D[K]=W end end return function(D)return function(K)local W=K.Parent K.Parent=nil local f=Instance.new(D)M(f,K)f.Parent=W return f end end
local function applyProperties(instance, properties)
	for key, value in properties do
		if type(key) == "number" and typeof(value) == "Instance" then
			value.Parent = instance

			continue
		end

		if type(value) == "table" then
			applyProperties(instance, value)

			continue
		end

		if typeof(instance[key]) == "RBXScriptSignal" then
			instance[key]:Connect(value)

			continue
		end

		instance[key] = value
	end
end

return function(class)
	return function(properties)
		-- We should set Parent last.
		local parent = properties.Parent
		properties.Parent = nil

		local instance = Instance.new(class)
		applyProperties(instance, properties)
		instance.Parent = parent

		return instance
	end
end
