Strange behavior with RemoteEvents and Tables, automatic conversion of keys to string

Hello,

I was making an inventory system for my game, but the table I got from a remote event couldn’t be read properly. Then, I realized that the key in the table was a string, even though it originally was a number at the server. To test this; I created a baseplate, put a RemoteEvent under ReplicatedStorage, and created 2 scripts:

Server Script:

local rs = game:GetService("ReplicatedStorage")
local remote = rs:FindFirstChild("RemoteEvent")

local plrs = game:GetService("Players")

local p = plrs.PlayerAdded:Wait()

remote:FireClient(p,
	{
		"hello"
	},
	{
		[1] = "abc"
	},
	{
		nil, "def"
	},
	{
		[2] = "ghi"
	}
)

Client Script:

local rs = game:GetService("ReplicatedStorage")
local remote = rs:FindFirstChild("RemoteEvent")

remote.OnClientEvent:Connect(print)

The output:
image

What even is void (in Roblox)? Why was the 4th table’s key converted to a string? Why was the third table’s 2nd key not converted to a string? Or is this a bug? Do I have to use tonumber?

This will likely help explain the behavior your getting. The parameter limitations section.

1 Like