Object Orientated Issues

I have been trying to improve my coding abilities, so I am currently messing around with Object Orientated. My issue is I can not get any member functions of the object to work properly. Im 90% sure this is one of those stupid things that is right in front of your face. Thanks.

Main``

local Supplier = require(script.SupplierHandler)

local Crate = Supplier.NewCrate(CFrame.new(Vector3.new(-38.3, 13.7, 7)))

Crate:PutCrateOnTruck(game.Workspace.Part.CFrame,Crate.Id)

Class

local CrateHandler = {};

CrateHandler.__Index = CrateHandler

local MetaTable = {}

function CrateHandler.NewCrate(Position)
	local Crate = {};
	setmetatable(Crate,CrateHandler);
	setmetatable(MetaTable,Crate);
	Crate.Model = SpawnCrate(CrateFolder,Position);
	Crate.Opened = false;
	Crate.Content = nil;
	return Crate;
end

function CrateHandler:CratePickUp()
	
end

function CrateHandler:PutCrateOnTruck(Object,Position,Id)

end

return CrateHandler

Capture

No joy

1 Like

If the Class script is a ModuleScript, you have to finish it off with:
return CrateHandler

I did just shortened it for readability and forgot to put it back in

Metatable members are case sensitive. Try __index.


I’m not sure what your MetaTable table is for. From the given code, it does nothing. If that’s the case, then you only need

setmetatable(Crate,CrateHandler);

and not

setmetatable(Crate,CrateHandler);
setmetatable(MetaTable,Crate);
1 Like

Thx

1 Like