function Replica.ListenToChildAdded(V,M)if type(M)~="\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[V.Id]==nil then return end local h=ChildListeners[V.Id]if h==nil then h={}ChildListeners[V.Id]=h end table.insert(h,M)return Madwork.NewArrayScriptConnection(h,M)end function Replica.FindFirstChildOfClass(V,M)for V,h in ipairs(V.Children)do if h.Class==M then return h end end return nil end
-- Children:
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
