Attempt to call a nil value

So I was trying to do something using Object Oriented Programming and created a class car with it’s own methods and properties.
This is my Module

This is how I am creating an object called car and trying to implement a method called start

local carmodule = require(script.Parent["Car Module "])

local mycar = carmodule.new()

mycar:Start() 

The error I am getting
`

ServerScriptService.Script:3: attempt to call a nil value - Server - Script:3

`

1 Like

did the Car Module return a table??

Yes the module returned the table Car.

Instead of using function Car:Start()
You have to use function Car.Start()
(the period instead of the colon)

Same goes with the “SetWheels” method.

Hope this helps!

1 Like

Also adding on to this…

mycar:Start()

should be carmodule.Start(mycar)

1 Like

can you tell me the source of the script that is requiring the car module?

1 Like

You forgot to set the index, so Car.__index = Car (in the module) underneath local Car.

1 Like

This is not true since the OP is using OOP when doing Car:Start() the colon is predefined self. Which means it would try to index the metatable, the reason of __index is so that it has a reference to where it should look.

1 Like