Hello so I am learning how to use metatables because before I never had any use of it.
So I will get straight to the point.
Module Script
local Pizza = { }
Pizza.__index = Pizza
function Pizza.new(flavor, slice_count)
local this = { }
this.Flavor = flavor
this.Slices = slice_count
setmetatable(this, Pizza)
return this
end
function Pizza:Eat()
if self.Slices <= 0 then return end
self.Slices -= self.Slices
end
return Pizza
Script
local modu = require(workspace.ModuleScript)
local p2 = modu.new("nicenice", 3)
p2:Eat()
print(p2.Slices)
When I run this I get Host:6: attempt to call a nil value
So on the 6th line it errors because its a nil value and I dont know why because I think I have declared the value.