(OOP) How do I run metamethods from another object?

I am fairly new to OOP and I made a grid. I wanted to add algorithms to this grid, so I created a new module and made Algorithm.new(grid). However, when I try to run a metamethod inside the grid using the new algorithm object, it just says that it indexes nil. Is there a way to connect the two meta tables?

local GridModule = require(game.ReplicatedStorage.OOPTests.Grid) -- grid module

local Prims = {}
Prims.__index = Prims

function Prims.new(grid,LowestWeight,HighestWeight,createGrid : boolean,GridSize,CellSize,OriginPosition)
	local newPrims = setmetatable({},Prims)
	newPrims.LowestWeight = LowestWeight
	newPrims.HighestWeight = HighestWeight
	if createGrid then
		local GridSize2 = GridSize or Vector3.new(5,5,0)
		local CellSize2 = CellSize or 2
		local Origin2 = OriginPosition or Vector3.new(0,CellSize2,0)
		newPrims.Grid = GridModule.new(GridSize2,CellSize2,Origin2)
		newPrims.Grid = grid
	return newPrims

function Prims:Run()
	local Cells = self.Grid:GetAllCells()	

I find this weird because when I run this on a server script instead of a module, it runs perfectly fine.

local gridModule = require(game.ReplicatedStorage.OOPTests.Grid)

local grid = gridModule.new(Vector3.new(5,5,0),2,Vector3.new(0,0,0))

local PrimsModule = require(game.ReplicatedStorage.OOPTests.AlgorithmGraphs.Prim)

local Prims = PrimsModule.new(grid,5,10,false)

server script if anyone is wondering.

After looking through my code over once, I realized that I forgot to put a colon instead of a period. Sorry if I wasted your time.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.