As the title says, I am wondering how to store and fire events in a module Script, preferably without using Bindable or Remote events.
Here is a simple example of what I am trying to say:
-- this is our 'a' metatable that I will use in this example.
local a = {}
a.__index = a
-- This is a regular function, nothing special about it
function a:Example()
print(self)
end
-- Here I will referance a part to use the function on.
local ReferancePart = Instance.new("Part")
ReferancePart.Parent = workspace
a.Example(ReferancePart)
--// output: 'part'
As you can see, there is a function there. of course I could also use return if I needed.
But how do I turn a.Example into an event so I can use a.Example:Connect() ?
I would just use a BindableEvent. You don’t have to parent it to anything, you can just Instance.new it and keep it around as a variable.
There are ways to re-implement event functionality with coroutines and things, but it would be more complicated, slightly slower, and would require any users to learn your custom solution rather than just having normal roblox-supported objects.
If you do want to still go the custom route and totally avoid BindableEvents for some reason, see this thread:
Specifically, the link to Quenty’s Signal class. (That actually uses a BindableEvent internally, just does some tricks to avoid deep-copying the table)
Specifically, the link to this solution which does not use BindableEvents. There are links to better implementations as well.