-- 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
