I’m pretty new to OOP, but I’m trying to get my tycoon plot system to run this update function right away, the problem is that when I run the script, the functions errors saying that it attempted to call a nil value. Does anyone know why and how to fix it?
Plot Module:
local Tile = require(script.Tiles)
local module = {}
function module:GetPlot(Plot)
local NewPlot = setmetatable({}, module)
self.Name = Plot.Name
self.Owner = Plot.Owner
self.Tiles = Tile:newFolder(Plot.FolderofTiles)
self.Tiles:UpdateTiles() -- Attempt to call a nil value
return NewPlot
end
return module
Tile Module:
local module = {}
function module:newFolder(FolderofTiles)
local tileFolder = setmetatable({}, module)
self.Tiles = FolderofTiles
return tileFolder
end
function module:UpdateTiles(SingleTile, hasReset)
print(self)
end
return module
1 Like
Looks like you named your self object to NewPlot, you might wanna fix this (this is on both modules)
I changed it but I still got the same error
-- Plot module
local Tile = require(script.Tiles)
local module = {}
function module:GetPlot(Plot)
local NewPlot = setmetatable({}, module)
print(Plot.Tiles)
NewPlot.Plot = Plot.Name
NewPlot.Owner = Plot.Owner
NewPlot.Tiles = Tile:newFolder(Plot.FolderofTiles)
NewPlot.Tiles:UpdateTiles()
return NewPlot
end
return module
---------------------------------------------------------------------------------
-- Tiles module
local module = {}
function module:newFolder(FolderofTiles)
local tileFolder = setmetatable({}, module)
tileFolder.tiles = FolderofTiles
return tileFolder
end
function module:UpdateTiles(SingleTile, hasReset)
print(self)
end
return module
Not 100% sure, but you could try naming them all to self instead
NEVERMIND, just realized I forgot to put .__index in each module, now they work!
1 Like