Can't set metatable to instance anymore


Hey everyone, I just experienced this bug when trying to set classes for an object, as I always could set it to an instance. Now, it doesn’t work. Have you been getting this issue as well, and if not is there any way around it?
the code btw: image

please show us the variables too?

It’s a module:
local module = {}

local MouseFunctions = require(script.Parent:WaitForChild("ManageFunctions"):WaitForChild("MouseFunctions"))

local ItemClass = {}
ItemClass.__index = ItemClass
local ItemTemplate = nil -- some item template,fill this in later

function ItemClass:DropItem(Position)
	local clone = self.Object.Value:Clone()
	clone.Parent = workspace
	clone:SetPrimaryPartCFrame(CFrame.new(Position))
	--The item will  have to be destroyed, with all the data relating to it as well
	self:Destroy()
	self.Object.Value = nil
end

function ItemClass:EquipInHand()
	
end
function module.AddItemClass(object)
	MouseFunctions.Mouse = module.Mouse
	MouseFunctions.Player = module.Player
	MouseFunctions.MainFrame = module.MainFrame
	MouseFunctions.onMouseHold(object)
	MouseFunctions.SpinHover(object)
	return setmetatable(object, ItemClass)
end

return module

The error is coming from the fact that the argument you are passing to AddItemClass is nil.

No, that’s incorrect. It’s a module, and I am requiring it.


the bug hasn’t occurred yet. I am guessing I messed something up, but it never happened before.
This is the script that requires it:

local MainFrame = script.Parent
local ViewportFrames = MainFrame:WaitForChild("ViewportFrames")
local player = game.Players.LocalPlayer
local replicatedStorage = game:GetService("ReplicatedStorage")
local InventorySystem = require(replicatedStorage:WaitForChild("Inventory"):WaitForChild("InventorySystem"))
local mouse = player:GetMouse()
local RS = game:GetService("RunService")
InventorySystem.Mouse = mouse
InventorySystem.Player = player
InventorySystem.MainFrame = MainFrame

for i, vp in pairs(ViewportFrames:GetChildren()) do
	InventorySystem.AddItemClass(vp.ViewPort)
end

You are passing an Instance to setmetatable, and it should get a table instead.

1 Like

but I never had to do that before. Instanced always worked in this matter.

Instances have never worked with setmetatable. Instances are userdata and the lua function “setmetatable” can only take in tables.

maybe try to do something like this:

{object}
1 Like

I’m trying to get the older versions right now, where this bug didn’t occur.

Ok so, I fixed the bug, but in a weird way.

local metareturn = {}
metareturn.__index = object
return setmetatable(class, metareturn)
1 Like