Data loss, numbers change to strings when going thru RemoteEvent/Function

When you pass an array that is missing the first key, it will automatically convert all the keys to strings. It is expected that the keys would remain as numbers

When you pass an array that is missing > 1 key in sequence, all data after the missing keys will be lost

-- Keys remain as numbers as expected
game.ReplicatedStorage.RemoteEvent:FireServer({[1] = true, [2] = true, [3] = true})

-- Keys converted to strings, expected to remain as numbers
game.ReplicatedStorage.RemoteEvent:FireServer({[2] = true, [3] = true, [4] = true})

-- Keys remain as numbers as expected
game.ReplicatedStorage.RemoteEvent:FireServer({[1] = true, [3] = true, [4] = true, [6] = true})

-- Keys remain as numbers, all data after hole in array (5, 6) is lost!
game.ReplicatedStorage.RemoteEvent:FireServer({[1] = true, [2] = true, [5] = true, [6] = true})

Output from above code
image

Repro, all code in ReplicatedStorage
NetworkBugs.rbxl (45.5 KB)

2 Likes

This behavior is documented:

1 Like

It is documented, but it would still be great if these issues were resolved. I want to be able to send an array with holes without losing any data and without the keys all turning to strings

This is due to the way our reflection system handles tables. I would describe it as undesirable behavior rather than a bug since, as you have shown, it’s not intuitive why your keys are being converted in some cases but not others.

In either case changing this could be difficult as experiences may unintentionally rely on this behavior. Since this is documented I am going to close this as not-a-bug but I’ll create a follow-up task to investigate if we can/should change this behavior.

Happy to chat more if you want me to go into more detail or you want to discuss further.