I do not understand __index

I do not know how to use __index. I started using metatables today and I somewhat understand it. I looked everywhere on how to do this and I do not understand.



Here is my code but I do not know what to do.

-- Module

local Class = {}
--Class.__index = Class
function Class.new()
	local self = setmetatable({},Class)
	self.Genie = "Off"
	self.__index = function(self,i)
		print("Testy") -- Not firing
		return self[i]
	return self

return Class

-- Local Script
local Class = require(game.ReplicatedStorage.Class)
local c = Class.new()

None of this makes sense it is just a test.
Where it says print(“Testyy”), It is not firing. How do I fix this?

self is not the metatable of anything, the a.__index = a idiom is popular in OOP so you can get the methods of the class on an instance. Not sure what you were trying to do here.