Recently, I decided to dive deeper into Object-Oriented Programming (OOP) because my code wasn’t readable, and I was interested in learning how module scripts and metatables work. So, I decided to create something myself, and this is how it turned out.
ModuleScript
donut = {}
donut.__index = donut
function donut.new(model,position,parent)
local newDonut = {}
setmetatable(newDonut,donut)
newDonut.Model = model
newDonut.Position = position
newDonut.Parent = parent
return newDonut
end
function donut:Enlarge()
self.Scale = self.Scale + 50
end
return donut
ServerScript
local donutModule = require(game.ReplicatedStorage.ModuleScript)
donut = donutModule.new(game.ReplicatedStorage.Donut,Vector3.new(-64.843, 3.281, 251.054),workspace)
donut:Enlarge()
However, I didn’t see the donut or the enlargement; instead, I had to face an error.
Appreciate any help or tips!
