Metatable Return

So I’m trying to return a metatable through a remotefunction and I’m running into issues where it won’t actually return, does anyone got any solution to this?

local myTable = {
  lol = 'hi'

setmetatable(myTable, {__index = function() return 'none found' end,})

local function remoteFunc(plr, index)
  return myTable[index] -- if the index isn't 'lol' then it will return 'none found'

RemoteFunction.OnServerEvent = remoteFunc

If the index isn’t ‘lol’ then it should return ‘none found’, but can you maybe send code or what metamethod you’re using exactly?

local CMod = require(Modules:WaitForChild("CMod"))
local function OnInvokedServer(Player, args)
local Char = Player.Character or Player.CharacterAdded:Wait()
local New = CMod.New(Char)

return New

Here’s the part, the oninvokedserver is from a remotefunction who’s server got invoked

Can’t be done.

1 Like

I saw there was a post about using module scripts instead of remote function to return it, but well I can’t find that post again.

You can make a workaround where you transmit the table itself and some identifier for the type of object it represents, like a number or a string. On the receiving end you then set the metatable again on the received table according to the type.