local PlayerStats = {}
PlayerStats.__index = PlayerStats
function PlayerStats.new()
local self = setmetatable({}, PlayerStats)
print("test")
end
return PlayerStats
Server
local PlayerStats = require(game:GetService("ReplicatedStorage").Modules.ModuleScript.leaderstats)
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = PlayerStats.new()
end)
Perhaps .new() is a reserved function?
Make sure there are no other scripts with the same name first; that’s sometimes easy to miss.
I don’t know what “__index” is supposed to do; why the two underscores? is that the name or supposed to do something else?
What do you mean by “don’t get passed”, I have used functions in modules before and they worked perfectly fine, yet this time it decided to break when trying OOP.
Are you sure it doesn’t work? I just replicated your code and it worked after adding the return statement.
Extra
local PlayerStats = require(game:GetService("ReplicatedStorage").ModuleScript) -- changed to match where I put mine.
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = PlayerStats.new()
end)
local PlayerStats = {}
PlayerStats.__index = PlayerStats
function PlayerStats.new()
local self = setmetatable({}, PlayerStats)
print("test")
return self
end
return PlayerStats
The error is saying that whatever you’re requiring doesn’t have a key named new. I’d print PlayerStats after requiring it just to double check that it’s what you expect.