How to teleport player from a table in a table

I have been trying to teleport player in a table that is in another table. The player is a string and it wants a player I’m guessing player inside game.Players but I’m not sure. I tried looping through the table but I don’t know how to look inside a table inside of a table.

Here’s my script

--//Settings//--
local placeID = 15559342116
--//Services//--
local teleportService = game:GetService("TeleportService")

--//Variables//--
local PlayerRemote = game.ReplicatedStorage.RemoteEvents.PlayerRemote

local playerToTeleport = {}

PlayerRemote.PlayerJoined.Event:Connect(function(player, chapter)
	if not playerToTeleport[chapter] then
		playerToTeleport[chapter] = {}
	end

	if not table.find(playerToTeleport[chapter], player) then
		table.insert(playerToTeleport[chapter], player)
	end
end)

PlayerRemote.PlayerLeft.Event:Connect(function(player, chapter)
	if playerToTeleport[chapter] then
		local index = table.find(playerToTeleport[chapter], player)
		if index then
			table.remove(playerToTeleport[chapter], index)
		end
	end
end)

function teleportLoop()
	wait(10) --teleport delay
	for chapter,player in ipairs(playerToTeleport) do
	local reservedID = teleportService:ReserveServer(placeID)
	teleportService:TeleportToPrivateServer(placeID, reservedID, player, nil, chapter)
	end
end

teleportLoop()

I only doesn’t understand this part on how I could get the player from a table.

	for chapter,player in ipairs(playerToTeleport) do
	local reservedID = teleportService:ReserveServer(placeID)
	teleportService:TeleportToPrivateServer(placeID, reservedID, player, nil, chapter)

the table looks like this

{
                    ["1"] =  ▼  {             --chapter
                       [1] = "Player1"          --player
                    }

I am unsure of how to implement it using your code where you have a larger array of names, but I do know a way of converting the player’s name from string to the player’s instance;

local Players = game:GetService("Players")

local player = "Iemny"  --//This acts as your table. Make sure a variable is set to get the player's name.
local playerInstance = Players:FindFirstChild(player)  --//Searches the player list for an instance match with the string

print(playerInstance)  --//As for result, it prints the player instance

Took me so long to figure out how to get it to work lol

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.