I’m somewhat new to scripting with OOP in mind, so remind me if I make a mistake or leave anything out by accident.
Currently, I have this setup where players have their metatable stored in this ‘Players Manager’ Module, so other scripts can access it whenever it needs to change something. For example, it would just get the metatable from the module and change some stuff in the player metatable.
The setup for adding the player metatable is in the Players Manager module:
local ps = game:GetService("Players")
local sss = game:GetService("ServerScriptService")
local Components = sss.Components
local PlayerComponent = require(Components.Player)
local Players = {
-- all the players will be in here
}
local function PlayerAdded(PlayerObject: Player)
local Player = PlayerComponent.New(PlayerObject)
Player:Init()
Players[PlayerObject] = Player -- setting index value for later use
end
ps.PlayerAdded:Connect(PlayerAdded)
return Players
btw, the player component is the thing making the metatable with the __index stuff and everything
I’m just wondering whether this is the correct or ideal way to store player data and stuff, or whether there are better ways to go about this with other design structures.