local z={}function z.CreateNewSignal(z)local c={}local I=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")local u={}function c.Connect(F,z)assert(c==F,"\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(z)=="\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(z))local P=I.Event:Connect(z)u[P]=true local S={}function S.Disconnect(z)assert(S==z,"\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")P:Disconnect()u[P]=nil end return S end function c.DisconnectAll(z)assert(c==z,"\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 z,c in pairs(u)do z:Disconnect()u[z]=nil end end function c.Wait(z)assert(c==z,"\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 I.Event:Wait()end function c.Fire(z,...)assert(c==z,"\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")I:Fire(...)end return c end return z
--[[
	Creates signals via a modulized version of RbxUtility (It was deprecated so this will be released for people who would like to keep using it.
	
	This creates RBXScriptSignals.
	
	API:
		table Signal:connect(Function f) --Will run f when the event fires.
		void Signal:wait() --Will wait until the event fires
		void Signal:disconnectAll() --Will disconnect ALL connections created on this signal
		void Signal:fire(Tuple args) --Cause the event to fire with your own arguments
		
		
		Connect, Wait, DisconnectAll, and Fire are also acceptable for calling (An uppercase letter rather than a lowercase one)
		
		
	Standard creation:
	
		local SignalModule = require(this module)
		local Signal = SignalModule:CreateNewSignal()
		
		function OnEvent()
			print("Event fired!")
		end
		
		Signal:Connect(OnEvent) --Unlike objects, this does not do "object.SomeEvent:Connect()" - Instead, the Signal variable is the event itself.
		
		Signal:Fire() --Fire it.
--]]

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
