function t.CreateSignal()local R={}local x=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")local K={}function R.Connect(t,I)if t~=R then error("\099\111\110\110\101\099\116 \109\117\115\116 \098\101 \099\097\108\108\101\100 \119\105\116\104 \096\058\096\044 \110\111\116 \096\046\096",2)end if type(I)~="\102\117\110\099\116\105\111\110"then error("\065\114\103\117\109\101\110\116 \035\049 \111\102 \099\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 "..type(I),2)end local U=x.Event:Connect(I)K[U]=true local d={}function d.disconnect(R)U:Disconnect()K[U]=nil end d.Disconnect=d.disconnect return d end function R.disconnect(x)if x~=R then error("\100\105\115\099\111\110\110\101\099\116 \109\117\115\116 \098\101 \099\097\108\108\101\100 \119\105\116\104 \096\058\096\044 \110\111\116 \096\046\096",2)end for R,x in pairs(K)do R:Disconnect()K[R]=nil end end function R.wait(K)if K~=R then error("\119\097\105\116 \109\117\115\116 \098\101 \099\097\108\108\101\100 \119\105\116\104 \096\058\096\044 \110\111\116 \096\046\096",2)end return x.Event:Wait()end function R.fire(K,...)if K~=R then error("\102\105\114\101 \109\117\115\116 \098\101 \099\097\108\108\101\100 \119\105\116\104 \096\058\096\044 \110\111\116 \096\046\096",2)end x:Fire(...)end R.Connect=R.connect R.Disconnect=R.disconnect R.Wait=R.wait R.Fire=R.fire return R end
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------Signal class begin------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
--[[
A 'Signal' object identical to the internal RBXScriptSignal object in it's public API and semantics. This function 
can be used to create "custom events" for user-made code.
API:
Method :Connect( function handler )
	Arguments:   The function to connect to.
	Returns:     A new connection object which can be used to disconnect the connection
	Description: Connects this signal to the function specified by |handler|. That is, when |fire( ... )| is called for
	             the signal the |handler| will be called with the arguments given to |fire( ... )|. Note, the functions
	             connected to a signal are called in NO PARTICULAR ORDER, so connecting one function after another does
	             NOT mean that the first will be called before the second as a result of a call to |fire|.

Method :disconnect()
	Arguments:   None
	Returns:     None
	Description: Disconnects all of the functions connected to this signal.

Method :fire( ... )
	Arguments:   Any arguments are accepted
	Returns:     None
	Description: Calls all of the currently connected functions with the given arguments.

Method :wait()
	Arguments:   None
	Returns:     The arguments given to fire
	Description: This call blocks until 
]]

function t.CreateSignal()
	local this = {}

	local mBindableEvent = Instance.new("BindableEvent")
	local mAllCns = {} --all connection objects returned by mBindableEvent::connect

	--main functions
	function this:Connect(func)
		if self ~= this then
			error("connect must be called with `:`, not `.`", 2)
		end
		if type(func) ~= "function" then
			error("Argument #1 of connect must be a function, got a " .. type(func), 2)
		end
		local cn = mBindableEvent.Event:Connect(func)
		mAllCns[cn] = true
		local pubCn = {}
		function pubCn:disconnect()
			cn:Disconnect()
			mAllCns[cn] = nil
		end
		pubCn.Disconnect = pubCn.disconnect

		return pubCn
	end

	function this:disconnect()
		if self ~= this then
			error("disconnect must be called with `:`, not `.`", 2)
		end
		for cn, _ in pairs(mAllCns) do
			cn:Disconnect()
			mAllCns[cn] = nil
		end
	end

	function this:wait()
		if self ~= this then
			error("wait must be called with `:`, not `.`", 2)
		end
		return mBindableEvent.Event:Wait()
	end

	function this:fire(...)
		if self ~= this then
			error("fire must be called with `:`, not `.`", 2)
		end
		mBindableEvent:Fire(...)
	end

	this.Connect = this.connect
	this.Disconnect = this.disconnect
	this.Wait = this.wait
	this.Fire = this.fire

	return this
end
