local T={}function T.CreateNewSignal(T)local S={}local v=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")local t={}function S.Connect(a,T)assert(S==a,"\069\120\112\101\099\116\101\100 \'\058\' \110\111\116 \'\046\' \099\097\108\108\105\110\103 \109\101\109\098\101\114 \102\117\110\099\116\105\111\110 \067\111\110\110\101\099\116")assert(typeof(T)=="\102\117\110\099\116\105\111\110","\065\114\103\117\109\101\110\116 \035\049 \111\102 \067\111\110\110\101\099\116 \109\117\115\116 \098\101 \097 \102\117\110\099\116\105\111\110\044 \103\111\116 \097 "..typeof(T))local u=v.Event:Connect(T)t[u]=true local R={}function R.Disconnect(T)assert(R==T,"\069\120\112\101\099\116\101\100 \'\058\' \110\111\116 \'\046\' \099\097\108\108\105\110\103 \109\101\109\098\101\114 \102\117\110\099\116\105\111\110 \068\105\115\099\111\110\110\101\099\116")u:Disconnect()t[u]=nil end return R end function S.DisconnectAll(T)assert(S==T,"\069\120\112\101\099\116\101\100 \'\058\' \110\111\116 \'\046\' \099\097\108\108\105\110\103 \109\101\109\098\101\114 \102\117\110\099\116\105\111\110 \068\105\115\099\111\110\110\101\099\116\065\108\108")for T,S in pairs(t)do T:Disconnect()t[T]=nil end end function S.Wait(T)assert(S==T,"\069\120\112\101\099\116\101\100 \'\058\' \110\111\116 \'\046\' \099\097\108\108\105\110\103 \109\101\109\098\101\114 \102\117\110\099\116\105\111\110 \087\097\105\116")return v.Event:Wait()end function S.Fire(T,...)assert(S==T,"\069\120\112\101\099\116\101\100 \'\058\' \110\111\116 \'\046\' \099\097\108\108\105\110\103 \109\101\109\098\101\114 \102\117\110\099\116\105\111\110 \070\105\114\101")v:Fire(...)end return S end return T


local Signal = {}

function Signal:CreateNewSignal()
	local This = {}

	local mBindableEvent = Instance.new('BindableEvent')
	local mAllCns = {} --All connection objects returned by mBindableEvent::connect
	
	--Note to scripters: the 'self' variable is built into lua. Any time a method in a table is called (table:somemethod()), a local variable in that function named "self" is created. This variable is an alias to whatever table the function is part of.

	function This:Connect(Func)
		assert(This == self, "Expected ':' not '.' calling member function Connect")
		assert(typeof(Func) == "function", "Argument #1 of Connect must be a function, got a "..typeof(Func))
		
		local Con = mBindableEvent.Event:Connect(Func)
		mAllCns[Con] = true
		local ScrSig = {}
		function ScrSig:Disconnect()
			assert(ScrSig == self, "Expected ':' not '.' calling member function Disconnect")
			
			Con:Disconnect()
			mAllCns[Con] = nil
		end
				
		return ScrSig
	end
	
	function This:DisconnectAll()
		assert(This == self, "Expected ':' not '.' calling member function DisconnectAll")
				
		for Connection, _ in pairs(mAllCns) do
			Connection:Disconnect()
			mAllCns[Connection] = nil
		end
	end
	
	function This:Wait()
		assert(This == self, "Expected ':' not '.' calling member function Wait")
		
		return mBindableEvent.Event:Wait()
	end
	
	function This:Fire(...)
		assert(This == self, "Expected ':' not '.' calling member function Fire")
		
		mBindableEvent:Fire(...)
	end
	return This
end

return Signal
