Data being lost when sending a table through a remote event

I’ve been working on a lobby system using remote events, and there is a problem where when I send a table of the current players in the hosts lobby, through a remote event, some players are removed from that table for whatever reason.

This is the code that is run on the client:

	local players = {}
	local playerSpawnNums = {}
	for i, v in pairs(game.Workspace.PlayerSpawn:GetChildren()) do
		if v:isA("BasePart") then
			for b, c in pairs(v:GetChildren()) do
				if c.ClassName == "Model" then
					table.insert(players, #players, c)
					table.insert(playerSpawnNums, #playerSpawnNums, v.Name)
				end
			end
		end
	end
	game.ReplicatedStorage.PlayerList.Join3:FireServer(players, playerSpawnNums, player)

And this is the code where the server recieves that array:

game.ReplicatedStorage.PlayerList.Join3.OnServerEvent:Connect(function(player, players, playerSpawnNums, ogPlayer)
        --the "players" variable is the table of the players
	game.ReplicatedStorage.PlayerList.Join4:FireClient(ogPlayer, players, playerSpawnNums, player)
end)

This is the tables results from the client:
client

This is the tables results from the server:
server

(Sorry if its obvious or something, im relatively new to lua)

1 Like

Can u just print out “players” table

Thanks for the reply. The pictures above are what happened when I printed out the table.

game.ReplicatedStorage.PlayerList.Join3:FireServer(players, playerSpawnNums, player)

You don’t need to send over player, unless that’s not the player.

The “player” variable is basically the player that is joining the lobby, so it’s needed later on in the code.

I am not sure if that helps but this part is atleast for me looking kinda weird:

table.insert(players, #players, c)

lets look at the table:

local players = {}

#players would be equal to 0. But in lua the first index is 1 so that means index of 0 doesnt actually exists.
It is recommended to do one of those two options:

table.insert(players, #players + 1, c)
--or
players[#players + 1] = c
2 Likes

thank you so much man, i couldnt figure out why it wasnt working, you mightve just saved our game!! !!! thank you !! !!!

1 Like