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
	--The item will  have to be destroyed, with all the data relating to it as well
	self.Object.Value = nil

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

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

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:

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