Skip to content

Instantly share code, notes, and snippets.

@howmanysmall
Last active August 1, 2021 03:25
Show Gist options
  • Select an option

  • Save howmanysmall/aba514429e27b579d4b7651372122d0b to your computer and use it in GitHub Desktop.

Select an option

Save howmanysmall/aba514429e27b579d4b7651372122d0b to your computer and use it in GitHub Desktop.
-- parry this you stupid deferred mode
local RbxScriptConnection = {}
RbxScriptConnection.ClassName = "RBXScriptConnection"
RbxScriptConnection.__index = RbxScriptConnection
function RbxScriptConnection.new(BindableEvent, Function)
return setmetatable({
Connected = true;
BindableEvent = BindableEvent;
Function = Function;
}, RbxScriptConnection)
end
function RbxScriptConnection:Disconnect()
if self.Connected then
local BindableEvent = self.BindableEvent
local Index = table.find(BindableEvent, self.Function)
if Index then
local Length = #BindableEvent
BindableEvent[Index] = BindableEvent[Length]
BindableEvent[Length] = nil
self.Connected = false
end
end
end
RbxScriptConnection.disconnect = RbxScriptConnection.Disconnect
function RbxScriptConnection:__tostring()
return "RBXScriptConnection"
end
local BindableEvent = {}
BindableEvent.ClassName = "BindableEvent"
BindableEvent.__index = BindableEvent
function BindableEvent.new()
local self = setmetatable({
Event = nil;
}, BindableEvent)
local Event = newproxy(true)
local Metatable = getmetatable(Event)
function Metatable.__index(_, Index)
if Index == "Connect" or Index == "connect" then
return function(_, Function)
return self:Connect(Function)
end
elseif Index == "Wait" or Index == "wait" then
return function()
return self:Wait()
end
else
error(string.format("%s is not a valid member of RBXScriptSignal", tostring(Index)), 2)
end
end
self.Event = Event
return self
end
function BindableEvent.Is(Value)
return type(Value) == "table" and getmetatable(Value) == BindableEvent
end
local function Finish(Thread, Success, ...)
if not Success then
warn(debug.traceback(Thread, tostring((...))))
end
return Success, ...
end
function BindableEvent:Fire(...)
for _, Function in ipairs(self) do
local Thread = coroutine.create(Function)
Finish(Thread, coroutine.resume(Thread, ...))
end
end
function BindableEvent:Wait()
local Thread = coroutine.running()
local function Yield(...)
local Index = table.find(self, Yield)
if Index then
local Length = #self
self[Index] = self[Length]
self[Length] = nil
end
Finish(Thread, coroutine.resume(Thread, ...))
end
table.insert(self, Yield)
return coroutine.yield()
end
function BindableEvent:Connect(Function)
table.insert(self, Function)
return RbxScriptConnection.new(self, Function)
end
function BindableEvent:Destroy()
for Index = 1, #self do
self[Index] = nil
end
setmetatable(self, nil)
end
BindableEvent.fire = BindableEvent.Fire
BindableEvent.destroy = BindableEvent.Destroy
function BindableEvent:__tostring()
return "BindableEvent"
end
return BindableEvent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment