Can't set dictionary as metatable?

I have an issue with this code

local CurrentUnit = nil
local Units = require(game.ServerStorage.ModuleScript)
local function deepCopy(original)
	local mt = getmetatable(original)
	local copy = {}
	for k, v in pairs(original) do
		if type(v) == "table" then
			v = deepCopy(v)
		end
		copy[k] = v
	end
	if mt ~= nil then
		print(mt)
		setmetatable(mt)
	end
	return copy
end

script.Parent.MouseButton1Click:Connect(function()
	CurrentUnit = deepCopy(Units.Defaults.MeleeCop)
	CurrentUnit.Model = CurrentUnit.Model:Clone()
	CurrentUnit:Cast()
end)

right before the error happens, mt is listed as the following:

17:58:00.261   ▼  {
                    ["Attack"] = "function",
                    ["Cast"] = "function",
                    ["CheckForward"] = "function",
                    ["Defaults"] =  ▶ {...},
                    ["InPlay"] = {},
                    ["MoveForward"] = "function",
                    ["__index"] =  ▶ {...},
                    ["new"] = "function"
                 }  -  Server - Script:13

The problem is that this isn’t how you use setmetatable. The formatting works like this:
setmetatable(a, b) - where b is your metatable. That way, under the correct circumstances, Lua pointers will guide a to b in the event that the tables have been linked.

local a = {}
local b = {}

a.Baz = function()
	print("Found!")
end

setmetatable(b, {__index = a})
b.Baz() -- Found!

I forgot about that bruh, thank you :pray:t2:

1 Like