Help with OOP and Metatables

Hi! I’m currently scripting a game that uses OOP and I’m having trouble;
Imagine I have Items that are related to a Player;

self.Player = Player

But if I want to call the metatable from a ServerScript, so I can for example call a object-related from the server, for example when a player buy coins and I have to call a certain method:

--from the server
local meta = (module).GetItemTableFromPlayer(player)

meta:addPoints()

How can I keep track of the metatables created in the module so I can call the functions across the script?

Modules have to be executed from a script. Modules really just store data, you can chose for that data to be code in OOP. That script running your OOP module would be storing all of that data.

Also, I think you may misunderstand what metadata is. “Meta” is not just any table with defined metadata. Metadata refers to the actual metamethods defined for any given table.

Finally, it would be much easier to help with your issue if I could see more of your code.

Are you talking about the objects you created with OOP? I feel like you might be confusing metatables with objects. If that’s the case, then you can just add a table that keeps track of the objects created, and append to that table when you invoke on the constructor. Here’s an example class (not tested):

local Car = {}
Car.__index = Car
local Cars = {}

function Car.new(player)
    local self = setmetatable({}, Car)
    self.player = player
    Cars[player] = self
    return self
end

function Car.getAllCars()
    return Cars
end

function Car.getCarFromPlayer(player)
    return Cars[player]
end

return Car