local module = {}

function module.new(CarType)
	local data = setmetatable({},{
		__index = module
	})

	data.Speed = 10
	data.CarType = CarType
	return data
end

function module:Boost()
	self.Speed = self.Speed + 1 --why does is self the data you returned in the constructor function?
end

return module

--Server script
local module = require(script.Parent:WaitForChild("Module"))

local car = module.new("idk")
car:Boost()

5 comments

1

you had a seizure with that comment on line 14 "why does is self the data you returned in the constructor function"

0

^ lol

0

oops

0

Why is self the data you returned in the constructor function

0

Do you know Python? self is used to refer to the Class that contains the given methods or your case here the functions, so "self" refers to "module". anytime you create a new function, "self" is automatically given in ROBLOX's Lua API, so every function really is function module.Name(self)