How can I send say, table = {“cheese”,“bread”}, through a RemoteEvent and have it return the same table, current when I would do :FireServer(table) it would only send cheese nothing else.
What’s the full table? It could be that you’re sending a table with mixed number and string keys.
See here for more information.
local table = {}
table[1] = game.Players.LocalPlayer.Name
table[2] = True1
table[3] = True2
table[4] = False1
ReplicatedStorage.Events.Send:FireServer(table)
You are making the table in-correctly.
True1 would make it fail due to it not being a valid type.
So on the client you’d make the table like this.
local Table = {
true,
false,
true,
false
}
Or if you were meaning for “True1” to be a string you’d do
local Table = {
"True1",
"False1",
}
Then you’d fire the remote with the table
Remote:FireServer(Table)
Then on the server you’d connect the remote.
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player: Player, tbl: {})
print(player.Name)
print(tbl)
end)
Output:
- You could send the table on remote event with:
:FireServer(game:GetService(“HttpService”):JSONEncode(Table))
- You could get the table by decoding it
game:GetService(“HttpService”):JsonDecode(Table)
- How to set it up?
Give the table using fire server (jsonencoded)
Get the table from fire server and use jsondecode on it
I recommend adding each element of the table as an extra parameter
— Client
local table = {“stuff”,”more stuff”}
RemoteEvent:FireServer(table[1],table[2])
— Server
RemoteEvent.OnServerEvent:Connect(function(player, stuff, morestuff)
print(stuff, morestuff) — prints elements
end)