Unable to use table with teleport data

  1. What do you want to achieve? I’m trying to get the player’s equipped items from the lobby inside of the game itself.

  2. What is the issue? Whenever I attempt to grab the table including the player’s items from the lobby, it returns nil.

  3. What solutions have you tried so far? I’ve changed variable names, made them local, searched on youtube, nothing worked so far.

Lobby Code:

local weapons = {}
for i,v in pairs(plrs) do
	weapons[v.UserId] = PlayerInformation[v.UserId].EquippedItems
end
local options = Instance.new("TeleportOptions")
options:SetTeleportData({
	["PlayerCount"] = #plrs,
	["Weapons"] = weapons
})

Printing the “weapons” table in the lobby returns:

{
   [168891080] =  ▼  {
       [1] = "Pistol",
       [2] = "AK-47"
   }
}

Problem is that, in my other game, I can’t seem to access the Weapons table.

local function plrAdded(plr)
	local joinData = plr:GetJoinData()
	local teleportData = joinData.TeleportData
	if teleportData then
		print(teleportData.Weapons) -- prints some weird "table: 0x093r39j" whatever in the console.
		for i,v in pairs(teleportData.Weapons) do
			print(i,v) -- prints "168891080 table: 23843200fwefws3e4" or something
		end
end

If I attempt to access that table at all (teleportData.Weapons[plr.UserId]) it returns nil

1 Like

have you tried using the name of the weapon? it seems to be detecting a table.

2 Likes

To view the contents of a table in the output, you have to disable log mode in the options

1 Like

I figured out your problem by the way, when you teleported you forgot to index your table.

local function plrAdded(plr)
	local joinData = plr:GetJoinData()
	local teleportData = joinData.TeleportData
	if teleportData then
		print(teleportData.Weapons[plr.UserId]) -- prints some weird "table: 0x093r39j" whatever in the console.
		for i,v in pairs(teleportData.Weapons) do
			print(i,v) -- prints "168891080 table: 23843200fwefws3e4" or something
		end
end