function Replica.ListenToChildAdded(X,N)if type(N)~="\102\117\110\099\116\105\111\110"then error("\091\082\101\112\108\105\099\097\067\111\110\116\114\111\108\108\101\114\093\058 \079\110\108\121 \097 \102\117\110\099\116\105\111\110 \099\097\110 \098\101 \115\101\116 \097\115 \108\105\115\116\101\110\101\114")end if Replicas[X.Id]==nil then return end local Y=ChildListeners[X.Id]if Y==nil then Y={}ChildListeners[X.Id]=Y end table.insert(Y,N)return Madwork.NewArrayScriptConnection(Y,N)end function Replica.FindFirstChildOfClass(X,N)for X,Y in ipairs(X.Children)do if Y.Class==N then return Y end end return nil end

function Replica:ListenToChildAdded(listener) --> [ScriptConnection] listener(replica)
	if type(listener) ~= "function" then
		error("[ReplicaController]: Only a function can be set as listener")
	end
	if Replicas[self.Id] == nil then
		return -- Replica is destroyed - listener will not be connected
	end
	-- Getting listener table for replica class:
	local listeners = ChildListeners[self.Id]
	if listeners == nil then
		listeners = {}
		ChildListeners[self.Id] = listeners
	end
	table.insert(listeners, listener)
	-- ScriptConnection which allows the disconnection of the listener:
	return Madwork.NewArrayScriptConnection(listeners, listener)
end

function Replica:FindFirstChildOfClass(replica_class) --> [Replica] or nil
	for _, child in ipairs(self.Children) do
		if child.Class == replica_class then
			return child
		end
	end
	return nil
end
