No
You are turning self into a number…Why?
Why do yall begginers want to turn everything into a class anyway?
OOP in such cases makes code harder,more unoptimized and harder to manage.
All you need to do is having one table always alive per player and having backend system that saves it upon player leaving/autosaving.
Also you absolutelly never use self,there no any point of using methods here anyway
Also if you are creating a constructur please either name it new or separate it from main table.
like:
local module = {}
module.__index = module
local function module:Method():string
return self.Name
end
return function(name:string)
local class = {Name=name}
return setmetatable(class,module)
end
Anyway if you were to use OOP, i recomend you to either use C like OOP or closures/closure OOP:
Example of closure OOP:
type closureClass = {
Increase:(num:number)->();
Print:()->();
Destroy: ()->();
}
local function NewClosure():closureClass
local num:number = 0
local connection = Script.Destroying:Connect(function():()
print(num)
end)
return {
Increase = function():()
num+=1
end;
Print = function():()
print(`Closure scope: {num}`)
end;
Destroy = function(self:closureClass):()
connection:Disconnect()
table.clear(self::{[any]:any})
end;
}::closureClass
end
local closure = NewClosure()
local Increase,Print = closure.Increase,closure.Print
Increase()
Increase()
Increase()
Increase()
Increase()
Print()
task.wait(5)
closure:Destroy()