Is there an efficient alternative for accessing player objects without searching through PlayersList?

local Aura = {}
local PlayersList = {}

Aura.__index = Aura

function Aura.new(player: Player, id: string)
	local self = setmetatable({}, Aura)
	
	self.player = player
	self.current = Auras:getAuraById(id)

	if not PlayersList[player.UserId] then
		PlayersList[player.UserId] = self
	end
	
	return self
end

this is efficient though?

you are seeing if the index exists, if it doesn’t you assign self to the index

2 Likes

Seems like the most efficient it could be.

And, this isn’t the same as “searching” through an array with something like table.find, because you’re using an index directly, which is much faster.