I recently noticed that when I have a client request a table from the server using a RemoteFunction, it doesn’t always send all of the information in the server table.
For example:
Server Output
Client Output
I used the Expressive Output beta feature to show a little better what I mean. But you can clearly see that both the table’s indices and one of the two sub-tables (half the data) is missing in the table received on the client.
Has anybody noticed this before? Is there a better method I should be using to send the data?
Currently I am just simply returning the master table associated with a particular key (in this case, “players”) through a RemoteFunction.
Further test notes - I tried using JSONEncode and JSONDecode to send the table across the client/server boundary but got even worse results because the sent tables lose any object references that were contained in the originals.
Furthermore, it only seems to occur (or lose data) when there’s a gap in the indices. For example, above where I sent a table with subtables at indices 1 and 3, the gap between the indices causes the data for 3 to be lost.
I also tried to use a deep table copy function to get an exact replica of the table for sending (in case there were any other interfering references) and had no luck.
I am now discovering that sometimes the tables are sent with specific indices, and other times there aren’t any. It is only when indices are specified that there are problems with missing data. Not sure why this is happening, but it seems to be directly correlated with the cause.
As @Club_Moo attempted to point out, you can’t send mixed tables through a remote, and it seems that roblox treats any table with a “nil” index between indicies as mixed.
If you were to have just 1 and 2, the table would send just fine, but having a nil value in between suddenly makes roblox go crazy. You could possibly just use 100% string indicies rather than numbers in order for the table to send properly, otherwise, just make sure your indicies are in order (1,2,3,4…) and they will send through just fine.
(deleted some previous replies to get rid of some irrelevant/incorrect information)
It’s more complicated than that. Probably the best way to describe it is if the # operator gives you
a >0 count, it will marshal indices 1…#. If it gives you 0, it will marshal all. Keep in mind that for
efficiencies’ sake, the # (length operator) will not always give you what you may expect.
I remember when I accidentally didn’t put the player parameter in the server script or accidentally added a player parameter in the client, this would happen. See if that’s the problem for you.
Thanks all for your input. After reading through the thread that @Club_Moo linked, it seems that it was the non-sequential indices that were giving me problems. To fix it, I just set those in-between indices ([2] in the example mentioned in the original post) to empty tables and then I do other checks in the code utilizing the data to make sure that there is information in the specific player table.
Looks like we’re good to go from here. Again, thanks for the help.
Sending a table through RemoteEvents with gaps in the indices sometimes makes it lose data. Although this seems to happen pretty randomly in my experience.