When the activator returns a setmetatable
, it can’t get all the info inside the table that was called. You will see the loader and the activator. However, the activator cannot recognize the table’s info, instead, it reads as {}
with no information. How can we fix this?
Activator:
return setmetatable({}, {__call = function(t)
print(type(t))
print(#t)
end })
Activator’s Results:
table
0
Loader:
local ran,res = pcall(function()
return require(script.Parent)
end)
if ran and res then
if type(res) == 'table' then
if res.LoaderId then
require(res.LoaderId)(res, res.LoaderId)
end
end
end
Try printing the table outside of the metamethod.
__call
(and its friends) are metamethods, which tells you that when you define it in “function” syntax as you have done, the first argument passed to it will actually be the table that the metatable is attached to. In your case, that table is empty, so the length operator correctly returns 0.
You can find this information on the DevHub, which you should always check first before making a support thread: Metatables | Documentation - Roblox Creator Hub
Method |
Description |
__call(table, …) |
Fires when the table is called like a function, … is the arguments that were passed. |
2 Likes
In the end, I forgot to add a return function when calling __call
function via metatable.