Event re-implements Roblox's event API (connect, fire, wait) by wrapping a BindableEvent.
This Event implementation is based on the Signal from Nevermore Engine by Quenty.
This implementation does not suffer from the restrictions normally introduced by using a BindableEvent. When firing a BindableEvent, the Roblox engine makes a copy of the values passed to BindableEvent:Fire. On the other hand, this class temporarily stores the values passed to fire, fires the wrapped BindableEvent without arguments. The values are then retrieved and passed appropriately.
This means that the exact same values passed to fire are sent to connected handler functions and also returned by wait, rather than copies. This includes tables with metatables, and other values that are normally not serializable by Roblox.
local zoneCapturedEvent = Event.new() -- Hook up a handler function using connect local function onZoneCaptured(teamName) print("The zone was captured by: " .. teamName) end zoneCapturedEvent:connect(onZoneCaptured) -- Or use wait, if you like that sort of thing local teamName while true do teamName = zoneCapturedEvent:wait() print("The zone was captured by: " .. teamName) end -- Trigger the event using fire zoneCapturedEvent:fire("Blue team") zoneCapturedEvent:fire("Red team") -- Remember to call cleanup then forget about the event when -- it is no longer needed! zoneCapturedEvent:cleanup() zoneCapturedEvent = nil
Constructs a new Event.
Connect a new handler function to the event.
Returns a connection object that can be disconnected.
Wait for fire to be called, then return the arguments it was given.
Fire the event with the given arguments.
All handlers will be invoked. Handlers follow Roblox Event conventions.
Disconnects all connected events to the Event.
Voids the Event as unusable.