local X=setmetatable local x=Instance local U=math local g=table local y={}y.__index=y function y.new()local U=X({},y)U._bindable=x.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")U._argMap={}U._bindable.Event:Connect(function(X)U._argMap[X]=nil end)return U end function y.Destroy(x)if x._bindable then x._bindable:Destroy()x._bindable=nil end X(x,nil)end function y.Fire(X,...)local x=U.random()X._argMap[x]=g.pack(...)X._bindable:Fire(x)end function y.Connect(x,X)return x._bindable.Event:Connect(function(U)local y=x._argMap[U]if y then X(g.unpack(y,1,y.n))end end)end function y.Once(x,X)return x._bindable.Event:Once(function(U)local y=x._argMap[U]if y then X(g.unpack(y,1,y.n))end end)end function y.Wait(X)local x=X._bindable.Event:Wait()local U=X._argMap[x]if U then return g.unpack(U,1,U.n)end end return y
local setmetatable = setmetatable
local Instance = Instance
local math = math
local table = table

local Signal = {}
Signal.__index = Signal

function Signal.new()
	local self = setmetatable({}, Signal)
	self._bindable = Instance.new("BindableEvent")
	self._argMap = {}

	-- Events connected first always fire last
	self._bindable.Event:Connect(function(key)
		self._argMap[key] = nil
	end)

	return self
end

function Signal:Destroy()
	if self._bindable then
		self._bindable:Destroy()
		self._bindable = nil
	end

	setmetatable(self, nil)
end

function Signal:Fire(...)
	local key = math.random()
	self._argMap[key] = table.pack(...)
	self._bindable:Fire(key)
end

function Signal:Connect(callback)
	return self._bindable.Event:Connect(function(key)
		local args = self._argMap[key]
		if args then
			callback(table.unpack(args, 1, args.n))
		end
	end)
end

function Signal:Once(callback)
	return self._bindable.Event:Once(function(key)
		local args = self._argMap[key]
		if args then
			callback(table.unpack(args, 1, args.n))
		end
	end)
end

function Signal:Wait()
	local key = self._bindable.Event:Wait()
	local args = self._argMap[key]

	if args then
		return table.unpack(args, 1, args.n)
	end
end

return Signal
