Feedback on my first OOP script

Everyone would be throwing rocks at me for not using metatables lol

local car = {}

function car.newCar(brand, year, model)
       local self = {}
       self.Brand = brand
       self.year = year
       self.model = model

       return self
end

local FiatUnoMille = car.NewCar("Fiat", 2005, "Fiat Uno Mille")

print(FiatUnoMille.brand)
print(FiatUnoMille.year)
print(FiatUnoMille.model)

return car
2 Likes

OOP is scary
It looks good although I never used it myself, but is it really worth the extra effort because modules just seem way more convenient.
But if you tried, I guess I could try OOP aswell.

That code looks nice, although metatables would improve its error handling and efficiency a lot. If you or anyone else doesn’t know how to use metatables but would like to, I think B Ricey does a good job on his YouTube channel explaining them in the “OOP in Roblox” Scripting tutorials.

OOP in Roblox Video #1: https://www.youtube.com/watch?v=2TC-bx0YfGk

1 Like

metatables are not needed, but if you want to integrate some custom functions, you’d need to make it dot notation and pass the “FiatUnoMille” yourself as opposed to just calling a method on FiatUnoMille

ex: module.modifyMe(FiatUnoMille, …)

I will be happy to give feedback if you want to add more to it. At the moment there is no problem with it.

Some things to consider, what is you want to create lorries, motor bike, quads etc… then maybe this should be vehicle and each vehicle would have it’s own type.

Happy to go in to more depth if you need

Looks good, just continue to read from the post you started :stuck_out_tongue:

1 Like