"Invalid table key type used" When Firing RemoteFunction

The title says it all. I have a module called “Network” for communicating between the server and clients. It has a table called “listRFuncs” which is an array that contains RemoteFunctions. The way it works is through an “InvokeClient” method which grabs the RemoteFunction from the table and invokes the client.

“self” and “plyr” don’t require explanations. “fid” is the index of the RemoteFunction and the rest the arguments to send.

Network.InvokeClient = function(self,plyr,fid,...)
	local rfunc = listRFuncs[fid]
	return rfunc:InvokeClient(plyr,...)
end

The error is “Invalid table key type used” at the return line. There is no table there which really confuses me.

I found the issue. It was the old mixed key table problem. In short, my server script sent an empty invoke, while the local script returned a table.

Going to add a gotcha that recently popped up for me to help people in the future.

If you attempt to send a table over a remote with this format:

{
    string = {
        5, 2, 7, 2345
    }
}
-- or --
{
    string = {
        [1] = 5;
        [2] = 2;
        [3] = 7;
        [4] = 2345;
    }
}

… it will successfully be passed over the client-server boundary.
However, if you try to send a table with the following format:

{
    string = {
        [2] = "element";
        [3] = "element #2";
        [4] = "element #3";
    }
}

… it will fail to pass. The numeric indices must be in numeric order, starting from 1. I’m not sure how often it is encountered by others but it was annoying enough to warrant me typing this out.

27 Likes