function Signal.Fire(j,...)for j,Z in pairs(j.connections)do task.spawn(Z.Handler,...)end if j.totalWaiting>0 then local Z=table.pack(...)for h,n in pairs(j.waiting)do j.waiting[h]=Z end end end Signal.fire=Signal.Fire function Signal.Connect(Z,j)if not(type(j)=="\102\117\110\099\116\105\111\110")then error(("\099\111\110\110\101\099\116\040\037\115\041"):format(typeof(j)),2)end local h=Z local n=HttpService:GenerateGUID(false)local W={}W.Connected=true W.ConnectionId=n W.Handler=j Z.connections[n]=W function W.Disconnect(j)h.connections[n]=nil W.Connected=false h.totalConnections-=1 if h.connectionsChanged then h.connectionsChanged:Fire(-1)end end W.Destroy=W.Disconnect W.destroy=W.Disconnect W.disconnect=W.Disconnect Z.totalConnections+=1 if Z.connectionsChanged then Z.connectionsChanged:Fire(1)end return W end Signal.connect=Signal.Connect function Signal.Wait(j)local Z=HttpService:GenerateGUID(false)j.waiting[Z]=true j.totalWaiting+=1 repeat heartbeat:Wait()until j.waiting[Z]~=true j.totalWaiting-=1 local h=j.waiting[Z]j.waiting[Z]=nil return unpack(h)end Signal.wait=Signal.Wait function Signal.Destroy(j)if j.bindableEvent then j.bindableEvent:Destroy()j.bindableEvent=nil end if j.connectionsChanged then j.connectionsChanged:Fire(-j.totalConnections)j.connectionsChanged:Destroy()j.connectionsChanged=nil end j.totalConnections=0 for Z,h in pairs(j.connections)do j.connections[Z]=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(...)
		task.spawn(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
