Skip to content

Instantly share code, notes, and snippets.

@nezuo
Last active Mar 2, 2021
Embed
What would you like to do?
local Signal = {}
Signal.__index = Signal
function Signal.new()
local self = setmetatable({}, Signal)
self._bindable = Instance.new("BindableEvent")
self._arguments = nil
self._argumentCount = nil
return self
end
function Signal:fire(...)
self._arguments = { ... }
self._argumentCount = select("#", ...)
self._bindable:Fire()
end
function Signal:connect(fn)
return self._bindable.Event:Connect(function()
fn(unpack(self._arguments, 1, self._argumentCount))
end)
end
function Signal:wait()
self._bindable.Event:Wait()
return unpack(self._arguments, 1, self._argumentCount)
end
function Signal:destroy()
if self._bindable == nil then
self._bindable:Destroy()
end
end
return Signal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment