I am working with object oriented programming with Roblox but it's not working so well, I'm making a class/object called 'Automotive' and one called 'Motorcycle', Automotive has function like Start, Stop, and properties with Gas, Speed. Motorcycle is an Automotive but with a Killswitch, but when I use Motorcycle.new() it doesn't have Start or Stop, any help?
Automotive:
local Automotive = {}
Automotive.__index = Automotive
Automotive.GasTank = 100
Automotive.Speed = 100
Automotive.new = function(modelNum)
local self = setmetatable({
ModelNumber = modelNum;
}, Automotive)
return self
end
function Automotive:Start()
print(tostring(self.ModelNumber).." started")
end
function Automotive:Stop()
print(tostring(self.ModelNumber).." stopped")
end
return Automotive
Motorcycle:
local Automotive = require(script.Parent.Automotive)
local Motorcycle = {}
Motorcycle.__index = Motorcycle
Motorcycle.new = function()
local NewMotorcycle = Automotive.new(tostring(math.random(1,100000)))
local self = setmetatable(NewMotorcycle,Motorcycle)
return self
end
function Motorcycle:Killswitch()
print(tostring(self.ModelNumber).." used kill switch")
end
return Motorcycle
Script:
local Motorcycle = require(script.Parent.Motorcycle)
local vec1 = Motorcycle.new()
vec1:Start()
Error:
ServerScriptService.Script:3: attempt to call method 'Start' (a nil value)

4 comments
Thank you! I am still new to OOP in Roblox and this will help me greatly in the future! Much love <3
@dualworlds Actually, :Start() and :Stop() work, but it doesn't check Motorcycle! When I try to run :Killswitch() on a Motorcycle object it says it can't find it!
Fixed, looked on a website about inheritance in Lua and found something, but you helped a lot, thanks!
I'm going to edit my answer to correctly fix the errors you mentioned. Thanks for bringing it up.