I started currently learning OOP a few days ago and I have found a tutorial on the Dev Forum that explains it and after trying out the code snippet below, it seemed to work. However, a few days later when I tried to run the code again, it just outputs the error, "ReplicatedStorage.Car:17: attempt to perform arithmetic (add) on nil and number"
Since I am very new to learning OOP, I have no idea how to fix this. Can someone please explain to me why it doesn't work.
The main problem is coming from the :Boost method, which uses the self keyword and it seems like the error comes from whenever the method is called.
I am sure I follow it corrected, as I put the put a module script in ReplicatedStorage which held the constructor and the :Boost method, and I put a normal script(--main script) in the ServerScriptStorage.
I copied the code directly from the forum, so I didn't think it was any typo made by me.
--module script called Car in game.ReplicatedStorage
Car = {}
Car.__index = Car
function Car.new(position, driver, model)
local newcar = {}
setmetatable(newcar, Car)
newcar.Position = position
newcar.Driver = driver
newcar.Model = model
return newcar
end
function Car:Boost()
self.Speed = self.Speed + 5
end
return Car
--main script
Car = require(game.ReplicatedStorage.Car)
newcar = Car.new()
newcar:Boost()

2 comments
You can use += now? I thought they didn't include this in Lua?
Oh mate how long ago they did... https://developer.roblox.com/en-us/resources/release-note/Release-Notes-for-435