Should I use object oriented programming when scripting in Lua?

Hello everyone, I am wondering whether I should use object oriented programming when coding in Lua.
When I searched it up, I got mixed responses, such as this one:

So, should I use object oriented programming? Thanks!

Like your linked post said, OOP is everywhere in ROBLOX. Every instance you use is an object that belongs to a class (e.g. BasePart, Humanoid) which has fields (e.g. Size, Health) and methods (e.g. Destroy(), Clone().) You can make your own custom classes as well.

For instance, instead of making a simple car model that you clone and manually adjust every time you want a new car, you could make a custom car class. In that class you could: define a general way to construct cars every time; write common variables like velocity, acceleration, and chassis color; write common methods like Brake() and ChangeColor(). OOP just makes everything less cluttered and much easier to manage.

So, it is a good idea to use OOP in lua?

Yes? It’s a little weird in ROBLOX because there’s no easy way to make a class, you have to do some trickery with metatables, but yes, it’s a good practice.

1 Like