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)
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: