Losing Table Data when Firing Event

Im making a inventory system for my game, explaining in a fast way, the client stores a local copy of his own data, when the server does something like adding an item to inventory or changing the money it fires a UpdateLocalData event with the new data as a argument and the client changes the old data for the new one, my problem is that the data on the server is right but the data that the client receives as the event argument is different.

--Server side
local data_g = PlayersData[player.Name]
	print("Inv2", data_g.Inventory)
	UpdateLocalData:FireClient(player, data_g, flags)
...

--Client side
UpdateLocalData.OnClientEvent:Connect(function(data, flags)
	print("data", data.Inventory)
...

image

I’m pretty sure you cant send entire tables through remote events and you have to use module scripts.

RemoteEvents cannot send mixed tables or sparse arrays. If you try and send a table with only numerical indexes that isn’t an array, the keys might get stringified to preserve the data, but I wouldn’t rely on that behavior.

Because there is an entry in your table at index 1, the engine interprets the table as an array. Because arrays are 1-based in Lua, the entry at index 0 is not considered to be in the array and is dropped as a result. You can resolve this issue by shifting everything over to be 1-based if your data is dense or create a new table for the purposes of networking where the keys are explicitly cast to strings.

1 Like

Thanks, I really didn’t know that Lua was 1-based.

1 Like