Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I properly set up the __index function?

I don't know why, but I literally forgot how to do that. I use __index for all my modules, but it is just doing setmetatable(table,{__index = table)}) so I don't remember how to set up the actual function. It was something like this:

local tab = {}
local tabMT = {

function tab.__index()
	return 1
end

}

however, it does not work.

1 answer

✓ Accepted answer

__index is set up like so:

local tab = {}
local mt = {
	
	__index = function()
		
		return 1
		
	end
	
}

setmetatable(tab,mt) -- and you can setmetatable, idk if you forgot to do that but just leaving it here

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.