So, the code you posted is an example of object oriented programming.
When people talk about “objects”, they’re really just referring to tables. Effectively every object in roblox is just a table. Module scripts themselves are tables, and the results of their source code are tables aka “objects”.
If you want to get into nuance here, the real advantage of object oriented programming is the ability to create constructor functions, which creates an object of a specific class, which can inherit properties and functions of other higher-level classes (which are just indices in a table)
For example –
Instance.new("Part")
Instance
is a class (aka table)
.new
is a constructor - which is a way of saying a function that returns a new object. The function is a value, and “new” is the key)
Part
is a paramater that specifies which new class of object you are trying to make.
If you go on the wiki and look at the page for Part, on the side column you’ll see something about ‘inherited from PVInstance’. You might be wondering “Well what’s PVInstance?” – its just another class that refers to a specific subset of Instances. In this case “PV” refers to Position & Velocity, i.e. these are physical objects in the workspace. All PVInstances fall under the umbrella of Instance
, but not all Instances are a PVInstance. The easier example would be BasePart
and Part
Why is it useful? Well remember that thing called inheritance? Classes can inherit properties, functions, etc. from other classes. This is where the role of Metatables comes in and allows you to create new classes without having to copy over every single bit of data from its ancestor class. You can also retroactively add functions to a higher level class that it’s children classes can then use without having to add that same function over and over. You can also add individual functions to individual classes as you find necessary. If you want to edit them, you only have to edit the function in one spot. Sound famiiar? It’s the same way they talk about module scripts, because its the same concept.
If we bring it full circle, OOP is the style of programming that enables you to create a top level class (e.g. Plane) and give it a series of properties, (method) functions, and whatever else you want, that it’s children classes (e.g. Jets, spyplanes, propeller planes, etc.) can all use, without having to rewrite each line of code for each individual class.
You should use it when it makes sense to use it, not because OOP is some magically superior form of coding. It’s why lots of people use it for guns, because a gun is relatively the same ignoring a few subtle changes between each property like damage, fire rate, etc.