function Signal.Fire(N,...)for N,R in pairs(N.connections)do R.Handler(...)end if N.totalWaiting>0 then local R=table.pack(...)for s,v in pairs(N.waiting)do N.waiting[s]=R end end end Signal.fire=Signal.Fire function Signal.Connect(R,N)if not(type(N)=="\102\117\110\099\116\105\111\110")then error(("\099\111\110\110\101\099\116\040\037\115\041"):format(typeof(N)),2)end local s=R local v=HttpService:GenerateGUID(false)local g={}g.Connected=true g.ConnectionId=v g.Handler=N R.connections[v]=g function g.Disconnect(N)s.connections[v]=nil g.Connected=false s.totalConnections-=1 if s.connectionsChanged then s.connectionsChanged:Fire(-1)end end g.Destroy=g.Disconnect g.destroy=g.Disconnect g.disconnect=g.Disconnect R.totalConnections+=1 if R.connectionsChanged then R.connectionsChanged:Fire(1)end return g end Signal.connect=Signal.Connect function Signal.Wait(N)local R=HttpService:GenerateGUID(false)N.waiting[R]=true N.totalWaiting+=1 repeat heartbeat:Wait()until N.waiting[R]~=true N.totalWaiting-=1 local s=N.waiting[R]N.waiting[R]=nil return unpack(s)end Signal.wait=Signal.Wait function Signal.Destroy(N)if N.bindableEvent then N.bindableEvent:Destroy()N.bindableEvent=nil end if N.connectionsChanged then N.connectionsChanged:Fire(-N.totalConnections)N.connectionsChanged:Destroy()N.connectionsChanged=nil end N.totalConnections=0 for R,s in pairs(N.connections)do N.connections[R]=nil end end Signal.destroy=Signal.Destroy Signal.Disconnect=Signal.Destroy Signal.disconnect=Signal.Destroy return Signal
-- METHODS
function Signal:Fire(...)
	for _, connection in pairs(self.connections) do
		connection.Handler(...)
	end
	if self.totalWaiting > 0 then
		local packedArgs = table.pack(...)
		for waitingId, _ in pairs(self.waiting) do
			self.waiting[waitingId] = packedArgs
		end
	end
end
Signal.fire = Signal.Fire

function Signal:Connect(handler)
	if not (type(handler) == "function") then
		error(("connect(%s)"):format(typeof(handler)), 2)
	end

	local signal = self
	local connectionId = HttpService:GenerateGUID(false)
	local connection = {}
	connection.Connected = true
	connection.ConnectionId = connectionId
	connection.Handler = handler
	self.connections[connectionId] = connection

	function connection:Disconnect()
		signal.connections[connectionId] = nil
		connection.Connected = false
		signal.totalConnections -= 1
		if signal.connectionsChanged then
			signal.connectionsChanged:Fire(-1)
		end
	end
	connection.Destroy = connection.Disconnect
	connection.destroy = connection.Disconnect
	connection.disconnect = connection.Disconnect
	self.totalConnections += 1
	if self.connectionsChanged then
		self.connectionsChanged:Fire(1)
	end

	return connection
end
Signal.connect = Signal.Connect

function Signal:Wait()
	local waitingId = HttpService:GenerateGUID(false)
	self.waiting[waitingId] = true
	self.totalWaiting += 1
	repeat
		heartbeat:Wait()
	until self.waiting[waitingId] ~= true
	self.totalWaiting -= 1
	local args = self.waiting[waitingId]
	self.waiting[waitingId] = nil
	return unpack(args)
end
Signal.wait = Signal.Wait

function Signal:Destroy()
	if self.bindableEvent then
		self.bindableEvent:Destroy()
		self.bindableEvent = nil
	end
	if self.connectionsChanged then
		self.connectionsChanged:Fire(-self.totalConnections)
		self.connectionsChanged:Destroy()
		self.connectionsChanged = nil
	end
	self.totalConnections = 0
	for connectionId, connection in pairs(self.connections) do
		self.connections[connectionId] = nil
	end
end
Signal.destroy = Signal.Destroy
Signal.Disconnect = Signal.Destroy
Signal.disconnect = Signal.Destroy

return Signal
