[URGENT!] How do I use BindableEvents in a module?

I’m working on a event system for my module, and I need a way to have events fire.
I’ve described the metatable like this: (reference to script)

local module = {}

function module:Test()
 local self  = metatable({
   TestEvent = Instance.new("BindableEvent")
}, module)

self.TestEvent:Fire()
end

return module

Client Example:

local module = require(game.ReplicatedStorage.MyModule)-- Just so you know I am actually requiring the actual module lol
local test = module:Test()

test.TestEvent.Event:Connect(function()
  print("module works!")
end)

But the client never prints anything.

Please help!

1 Like

you need to return self in your module:Test() function

That still hasn’t fixed it:

local module = {}

function module:Test()
 local self  = metatable({
   TestEvent = Instance.new("BindableEvent")
}, module)

self.TestEvent:Fire()
return self
end

return module

oh i see it now, replace metatable with setmetatable

local module = {}

function module:Test()
 local self  = setmetatable({
   TestEvent = Instance.new("BindableEvent")
}, module)

self.TestEvent:Fire()
return self
end

return module

That uhm, still didn’t quite fix it. I don’t have much of a knowledge on this.

i’m assuming you’re trying to make an OOP class?

usually the way people would do it is to do this:

local module = {}
module.__index = module --this was the line you needed to have in your code

function module.new()
	local self = setmetatable({}, module)

	return self
end

function module:Test()
	print('yo')
end

return module

and then to use that class it would be:

local class = require([where your class would be])

local test = class.new()
test:Test()

and the output should print yo. sorry about the earlier posts, i didn’t get what you were trying to do lol

if you wanna learn more about OOP, there’s a good post dedicated to it: