In what kinds of situations do u use metatables?


I was wondering in what kind of situations you should use metatables. I really don’t get the difference between metatables and normal tables.

Almost never. They sound cool (and frankly are cool) and so people get overexcited by them, but they don’t live up to the hype. I even hear things such as “I’m not sure how the game was hacked, but probably they had to use metatables.” But frankly they aren’t that impressive.

A metatable is just a table that can detect certain actions. It can detect when you try to access it. It can detect when you try to write to it. It can detect when you try to multiply two tables together. These can be individually useful in their own regards, but if you pair them all together you can create your own custom data types. You could create, for example, a Vector4 or even a Vector39, but I don’t know why you would want to. It’s just an example of course.

You can use them for object oriented programming mostly (which I described a little above), but even that tends to be a tad overused on Roblox, however it’s not without purpose.
The only situation where I think metatables are worth using is when you are making public modules and want other developers to have ease of use. And also for object oriented programming should you go that route.