I’ve been messing around with metatables and metamethods. Specifically, I have my own Timer metatable that calls functions after a delay (i know task.delay exists, its unrelated), and I’ve ran into an issue with __newindex.
For some reason, after using rawset, Roblox decides to stop using __newindex. I’m using __newindex so I can start/stop the Timer without calling a specific function.
Well, it does what it says on the tin; __newindex. It’ll only be invoked when a new index is created, but after the rawset, the index already exists because of the rawset, so the metamethod isn’t invoked.
That’s not right, __newindex is called when you set a value to the index. The name is irrelevant to whether or not the index has a value associated.
Besides, I use a few rawset functions that happen before the specific one that’s causing my issue. I can use something like Timer.Duration = 2 several times to invoke __newindex repeatedly.
__newindex is for setting values, __index is used for getting values.
Also clarifying, I’m not using setmetatable() after the table’s first assigned a metatable