Teleport a group of Players in a list?

{sry for bad english}

Ok my problem is :
I made a queue system and if a player join the queue a new StringValue will be created and the Name is of the StringValue is the player name (StringValue is in a Folder)
ok then i need to teleport them i did this with that script :

(the script is placed in an IntValue in the Queue Folder)

local placeId = 3595658973
local TeleportService = game:GetService("TeleportService")
script.Parent.Changed:Connect(function()
	if script.Parent.Value >1 then
		print("starting in 20")
		wait(20)
		if script.Parent.Value >1 then
			for _,v in pairs(script.Parent.Parent:GetChildren()) do
				if v:IsA("StringValue") then
					

				local pl = game.Players:GetPlayers(v.Name)
					local reservedServer = TeleportService:ReserveServer(placeId)

TeleportService:TeleportToPrivateServer(placeId, reservedServer, pl)

				end
		end
		end
		end
end)

But all players are teleported in the game

I’ve tried everything and it’s still teleporting everyone

The :GetPlayers() method always returns all the players in an array. The argument you placed inside it does nothing. If you’re trying to get a singular player, do this:

local pl = game.Players:FindFirstChild(v.Name) 

Since :TeleportToPrivateServer() takes an array of players, the player argument should be wrapped in curly brackets:

TeleportService:TeleportToPrivateServer(placeId, reservedServer, {pl} )

As a heads up, the variable pl could return nil if the player happens to leave mid process. Make sure to check for this.

2 Likes

Here,

local pl = game.Players:GetPlayers(v.Name)

Gets all the players [GetPlayers gets every player, it has no arguments.]
Instead, try placing the actual player in a table:

local actual = game:GetService("Players"):FindFirstChild(v.Name)
local pl = {actual}

And then

local reservedServer = TeleportService:ReserveServer(placeId)

TeleportService:TeleportToPrivateServer(placeId, reservedServer, pl)
3 Likes

thank you so much!
I’m so stupid xD