function Signal.Fire(A,...)A._bindableEvent:Fire(...)end function Signal.Connect(o,A)if not(type(A)=="\102\117\110\099\116\105\111\110")then error(("\099\111\110\110\101\099\116\040\037\115\041"):format(typeof(A)),2)end local c=o._bindableEvent.Event:Connect(function(...)A(...)end)if o.connectionsChanged then o.totalConnections+=1 o.connectionsChanged:Fire(1)local A A=(game:GetService("\082\117\110\083\101\114\118\105\099\101")).Heartbeat:Connect(function()if c.Connected==false then A:Disconnect()if o.connectionsChanged then o.totalConnections-=1 o.connectionsChanged:Fire(-1)end end end)end return c end function Signal.Wait(A)local o=A._bindableEvent.Event:Wait()return unpack(o)end function Signal.Destroy(A)if A._bindableEvent then A._bindableEvent:Destroy()A._bindableEvent=nil end if A.connectionsChanged then A.connectionsChanged:Fire(-A.totalConnections)A.connectionsChanged:Destroy()A.connectionsChanged=nil A.totalConnections=0 end end Signal.destroy=Signal.Destroy Signal.Disconnect=Signal.Destroy Signal.disconnect=Signal.Destroy return Signal

function Signal:Fire(...)
	self._bindableEvent:Fire(...)
end

function Signal:Connect(handler)
	if not (type(handler) == "function") then
		error(("connect(%s)"):format(typeof(handler)), 2)
	end
	
	local connection = self._bindableEvent.Event:Connect(function(...)
		handler(...)
	end)
	
	-- If ``true`` is passed for trackConnectionsChanged within the constructor this will track the amount of active connections
	if self.connectionsChanged then
		self.totalConnections += 1
		self.connectionsChanged:Fire(1)
		local heartbeatConection
		heartbeatConection = game:GetService("RunService").Heartbeat:Connect(function()
			if connection.Connected == false then
				heartbeatConection:Disconnect()
				if self.connectionsChanged then
					self.totalConnections -= 1
					self.connectionsChanged:Fire(-1)
				end
			end
		end)
	end

	return connection
end

function Signal:Wait()
	local args = self._bindableEvent.Event:Wait()
	return unpack(args)
end

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
		self.totalConnections = 0
	end
end
Signal.destroy = Signal.Destroy
Signal.Disconnect = Signal.Destroy
Signal.disconnect = Signal.Destroy



return Signal
