local Q={}Q.__index=Q function Q.new(Y)local G=setmetatable({_handlerListHead=false},Q)if Y then G.totalConnections=0 G.connectionsChanged=Q.new()end return G end function Q.Connect(Y,Q)local G=Connection.new(Y,Q)if Y._handlerListHead then G._next=Y._handlerListHead Y._handlerListHead=G else Y._handlerListHead=G end if Y.connectionsChanged then Y.totalConnections+=1 Y.connectionsChanged:Fire(1)end return G end
-- Signal class
local Signal = {}
Signal.__index = Signal

function Signal.new(createConnectionsChangedSignal)
	local self = setmetatable({
		_handlerListHead = false,
	}, Signal)
	if createConnectionsChangedSignal then
		self.totalConnections = 0
		self.connectionsChanged = Signal.new()
	end
	return self
end

function Signal:Connect(fn)
	local connection = Connection.new(self, fn)
	if self._handlerListHead then
		connection._next = self._handlerListHead
		self._handlerListHead = connection
	else
		self._handlerListHead = connection
	end

	if self.connectionsChanged then
		self.totalConnections += 1
		self.connectionsChanged:Fire(1)
	end
	return connection
end
