rev_ReplicaCreate.OnClientEvent:Connect(function(B,d)local Y={}if type(B)=="\116\097\098\108\101"then table.sort(B,function(B,d)return B[1]<d[1]end)for B,d in ipairs(B)do CreateReplicaBranch(d[2],Y)end elseif d[1]~=nil then CreateReplicaBranch({[tostring(B)]=d},Y)else CreateReplicaBranch(d,Y)end table.sort(Y,function(B,d)return B.Id<d.Id end)for B,d in ipairs(Y)do local Y=d.Parent if Y~=nil then local B=ChildListeners[Y.Id]if B~=nil then for Y=1,#B,1 do B[Y](d)end end end end for B,d in ipairs(Y)do NewReplicaSignal:Fire(d)local Y=ClassListeners[d.Class]if Y~=nil then Y:Fire(d)end end end)
-- Replica creation:
rev_ReplicaCreate.OnClientEvent:Connect(
	function(param1, param2) -- (top_replica_id, {replica_data}) OR (top_replica_id, {creation_data}) or ({replica_package})
		--[[
	param1 description:
		top_replica_id = replica_id
		OR
		replica_package = {{replica_id, creation_data}, ...}
	param2 description:
		replica_data = {replica_class, replica_tags, data_table, parent_id / 0, write_lib_module / nil}
		OR
		creation_data = {["replica_id"] = replica_data, ...}
	--]]
		local created_replicas = {}
		-- Unpacking replica data:
		if type(param1) == "table" then -- Replica package
			table.sort(param1, function(a, b) -- Sorting top level replicas by their id
				return a[1] < b[1]
			end)
			for _, replica_branch_entry in ipairs(param1) do
				CreateReplicaBranch(replica_branch_entry[2], created_replicas)
			end
		elseif param2[1] ~= nil then -- One replica data
			CreateReplicaBranch({ [tostring(param1)] = param2 }, created_replicas)
		else -- Creation data table
			CreateReplicaBranch(param2, created_replicas)
		end
		-- Broadcasting replica creation:
		table.sort(created_replicas, function(a, b)
			return a.Id < b.Id
		end)
		-- 1) Child added:
		for _, replica in ipairs(created_replicas) do
			local parent_replica = replica.Parent
			if parent_replica ~= nil then
				local child_listener_table = ChildListeners[parent_replica.Id]
				if child_listener_table ~= nil then
					for i = 1, #child_listener_table do
						child_listener_table[i](replica)
					end
				end
			end
		end
		-- 2) New Replica and Replica of class created:
		for _, replica in ipairs(created_replicas) do
			NewReplicaSignal:Fire(replica)
			local class_listener_signal = ClassListeners[replica.Class]
			if class_listener_signal ~= nil then
				class_listener_signal:Fire(replica)
			end
		end
	end
)
