How to create objects in LUA?

I normally like to stick to languages like Java and and Javascript and I know that creating a class in Javascript is

class Car {
type;
year;

constructor(type, year) {
          this.type = type;
          this.year = year;
     }
}

And java this

File: Car.java
public class Car {
     String type;
     int year;

     public Car(String type, int year) {
          this.type = type;
          this.year = year;
     }
}

And for making a new object it’s as easy is as this

Java: Car test = new Car("Car", 2005);
JavaScript: let test = new Car("Car", 2005);

My main question is that how can I create a simple class like the one I showed above and how can I make a new Instance of it in LUA? I’m thinking of making some sort of ticket system, and I think that using objects would be more clean then using variables

There is a tutorial all about OOP which is what you want.

PS: Lua is a name, not an acronym.

1 Like

I know LUA is a name, I just like to capitalize it, not sure why, it’s just a habit, though thanks, I’ll look at that

Ah, yes Java OOP, I use that often. Never used it in Lua though.

If you are used to java then I suggest you use this:

https://devforum.roblox.com/t/advanced-oop-implementation/741988?u=dthecoolest

It handles the metatable workaround stuff that you have to do in LUA to emulate objects.

3 Likes