local f={}function f.new()local f={}local e=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")local t=nil local I=nil function f.fire(f,...)t={...}I=select("\035",...)e:Fire()end function f.connect(S,f)if not f then error("\099\111\110\110\101\099\116\040\110\105\108\041",2)end return e.Event:connect(function()f(unpack(t,1,I))end)end function f.wait(f)e.Event:wait()assert(t,"\077\105\115\115\105\110\103 \097\114\103 \100\097\116\097\044 \108\105\107\101\108\121 \100\117\101 \116\111 \058\084\119\101\101\110\083\105\122\101\047\080\111\115\105\116\105\111\110 \099\111\114\114\117\112\116\105\110\103 \116\104\114\101\097\100\114\101\102\115\046")return unpack(t,1,I)end return f end return f
--[[
	class Signal

	Description:
		Lua-side duplication of the API of Events on Roblox objects. Needed for nicer
		syntax, and to ensure that for local events objects are passed by reference
		rather than by value where possible, as the BindableEvent objects always pass
		their signal arguments by value, meaning tables will be deep copied when that
		is almost never the desired behavior.

	API:
		void fire(...)
			Fire the event with the given arguments.

		Connection connect(Function handler)
			Connect a new handler to the event, returning a connection object that
			can be disconnected.

		... wait()
			Wait for fire to be called, and return the arguments it was given.
--]]

local Signal = {}

function Signal.new()
	local sig = {}

	local mSignaler = Instance.new('BindableEvent')

	local mArgData = nil
	local mArgDataCount = nil

	function sig:fire(...)
		mArgData = {...}
		mArgDataCount = select('#', ...)
		mSignaler:Fire()
	end

	function sig:connect(f)
		if not f then error("connect(nil)", 2) end
		return mSignaler.Event:connect(function()
			f(unpack(mArgData, 1, mArgDataCount))
		end)
	end

	function sig:wait()
		mSignaler.Event:wait()
		assert(mArgData, "Missing arg data, likely due to :TweenSize/Position corrupting threadrefs.")
		return unpack(mArgData, 1, mArgDataCount)
	end

	return sig
end

return Signal