If you want to do this with the constructor, you can do something like this:
local class = {}
class.__index = class
function class.new(test : number)
local self = setmetatable({}, class)
self.test = test
return test
end
return { hit = class } -- Like this, so now, you have to type out module.hit.new.
if you want to make it for methods, I think you can just make 2 classes, an inner and outer one, so when the outer class gets called, it makes a new inner class object with all the methods, though probably not the best solution probably.
like this:
local innerClass = {}
innerClass.__index = innerClass
local outerClass = {}
outerClass.__index = outerClass
function innerClass.new()
local self = setmetatable({}, innerClass)
return self
end
function innerClass:test()
print("The test function is working")
end
function outerClass.new()
local self = setmetatable({}, outerClass)
self.tbl = innerClass.new()
return self
end
return outerClass
here is how you can use it:
local mod = require("@self/ModuleScript") -- module location
local a = mod.new()
print(a.tbl:test())