Teleport player data to a private server

I want to send a table of players who teleport, but I can’t get this data

I would be very grateful if you could help me send the data

Server Teleport Full Script

local TS = game:GetService("TeleportService")
local TweenService = game:GetService("TweenService")
local placeId = "13646923072" -- Enter a second Id Place.
local leaveGuiEvent = game.ReplicatedStorage.LeaveGuiEvent
local TransitionEvent = game.ReplicatedStorage.TransitionEvent
local list = {}
local WaitForPlayers={}
local billboard = script.Parent.billboardPart.billboardGui
local timer
local teleporting = false
local spawnTeleport = script.Parent.spawn

local function updateGui()
	billboard.Frame.players.Text = "Players: " ..#list.. "/4" -- Change the number 16 according to the Max Player who want to be teleported.
end

local function removeFromList(character)
	for i=1,#list do
		if list[i] == character.Name then
			table.remove(list,i)
			updateGui()
		end
	end
end

local function teleportPlayers()
	if #list >= 1 then
		billboard.Frame.Status.Text = "TELEPORTING"
		billboard.Frame.Status.TextColor3 = Color3.fromRGB(255, 0, 0)
		local playersToTeleport = {}
		local WaitForPlayers={}
		local teleportTime = 0
		for i=1,#list do
			if game.Players:findFirstChild(list[i]) then
				table.insert(playersToTeleport,game.Players:findFirstChild(list[i]))
				table.insert(WaitForPlayers,game.Players:findFirstChild(list[i]).Name)
				TransitionEvent:FireClient(game.Players:findFirstChild(list[i]))
			else
				table.remove(list,i)	
			end
		end 
		teleporting = true
		local code = TS:ReserveServer(placeId)
		local teleportOptions = Instance.new("TeleportOptions")
		teleportOptions:SetTeleportData("WaitForPlayers", WaitForPlayers)
		TS:TeleportToPrivateServer(placeId,code,playersToTeleport,teleportOptions)
		repeat wait() until #list <= 0
		billboard.Frame.Status.Text = "READY"
		billboard.Frame.Status.TextColor3 = Color3.fromRGB(255, 0, 0)
		teleporting = false
	end
end

script.Parent.Gate.Touched:Connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") then
		if teleporting == false then
			local char = hit.Parent
			local player = game.Players:FindFirstChild(char.Name)
			local alreadyExists = false

			for i=1,#list do
				if list[i] == char.Name then
					alreadyExists = true
				end
			end

			if alreadyExists == false then
				if #list < 4 then -- Many Players have been teleported.
					table.insert(list,char.Name)
					char.PrimaryPart.CFrame = spawnTeleport.CFrame
					updateGui()
					leaveGuiEvent:FireClient(player)
				end

				player.CharacterRemoving:connect(function(character)
					removeFromList(character)
				end)
			end

		end
	end
end)

leaveGuiEvent.OnServerEvent:Connect(function(player)
	if player.Character then
		player.Character.HumanoidRootPart.Anchored = false
		wait()
		player.Character.Humanoid.Jump = true
		wait()
		player.Character:MoveTo(workspace.leaveRoomPart.Position)
		removeFromList(player.Character)
	end
end)

while wait() do
	timer = 31
	for i=1,timer do
		timer = timer - 1
		billboard.Frame.time.Text = timer
		wait(1)
	end
	teleportPlayers()
end

Teleport Function

    local function teleportPlayers()
	if #list >= 1 then
		billboard.Frame.Status.Text = "TELEPORTING"
		billboard.Frame.Status.TextColor3 = Color3.fromRGB(255, 0, 0)
		local playersToTeleport = {}
		local WaitForPlayers={}
		local teleportTime = 0
		for i=1,#list do
			if game.Players:findFirstChild(list[i]) then
				table.insert(playersToTeleport,game.Players:findFirstChild(list[i]))
				table.insert(WaitForPlayers,game.Players:findFirstChild(list[i]).Name)
				TransitionEvent:FireClient(game.Players:findFirstChild(list[i]))
			else
				table.remove(list,i)	
			end
		end 
		teleporting = true
		local code = TS:ReserveServer(placeId)
		local teleportOptions = Instance.new("TeleportOptions")
		teleportOptions:SetTeleportData("WaitForPlayers", WaitForPlayers)
		TS:TeleportToPrivateServer(placeId,code,playersToTeleport,teleportOptions)
		repeat wait() until #list <= 0
		billboard.Frame.Status.Text = "READY"
		billboard.Frame.Status.TextColor3 = Color3.fromRGB(255, 0, 0)
		teleporting = false
	end
end

Get Player Data

local RE = game:GetService("ReplicatedStorage")
local TS = game:GetService("TeleportService")
local PL = RE.GetTeleportPlayers

PL.OnClientEvent:Connect(function()
	local data = TS:GetLocalPlayerTeleportData()
	PL:FireServer(data)

	if data ~= nil then
		print("Data:")
		for i, v in pairs(data) do
			print(v)
		end
	else
		print("No Data")
	end
end)


2 Likes