How can i teleport player to the same reserved server?

okay so, long story short i made a queue system…
When u touch a part it puts u in the queue table… when there are more than 1 player in the table it will run a function:

local function tpPlayers(player)
	local server = tp:ReserveServer(7818885541)
	
	tp:TeleportToPrivateServer(7818885541, server, {player})
end

the “player” is just the player on the table.
The thing works perfectly it teleports u and everything but it wont teleport them to the same server, how will i do that?
i tried doing an in pairs loop but it doesn’t work.
How would i approach this problem?

1 Like

You might be able to use PrivateServerId with HttpService to teleport them to the same server. If this isn’t what you are going for then I’m not sure you explained it well enough. I haven’t personally used private servers but I’m going off of a guess.

https://developer.roblox.com/en-us/api-reference/property/DataModel/PrivateServerId

1 Like

Is “player” just a single player object? If so then only 1 player will be teleported.

1 Like

Oh wait I honestly didn’t even see that.

1 Like

You should pass an array of players to the function named “tpPlayers”, you can name the variable something like “players” (might be taken) or “playersToTp” etc. Then all you’ll need to do is pass that variable as an argument to the function, then inside the function “{player}” can be replaced with “playersToTp” or whatever the variable is named since the variable itself is a reference to an array of player objects. With this, all the players in the queue should be sent to the same server.

1 Like

Yeah… player is just 1 player, thats why im asking here at the forum, im out of ideas on how to teleport them with player 1

I provided the solution above, send the entire players array (queue of players wanting to teleport) to the function.

1 Like

I’m pretty sure he just wants 2 people in one server

1 Like

so, just get the table (which im expecting the script already has stored everyone in) and just make it an array or its already an array… i dont remember honestly

Then he can add an if statement check:

if #playersQueue >= 2 then
	--perform the action
end
1 Like

No, i can be 2 players or more… if i wanted 2 players only i could have done table[1] and table[2]

Can you provide more of the script?

well you stated, “The other player to the same server”

Im actually eating dinner its like midnight for me, give me a second lol

well not exactly, but the explanation sort of just “stated” that.

The other player thing is just an example since im only making this for me and my friend.

Here is the full script:

local queuePart = game.Workspace.Queue
local InQueue = {}
local tp = game:GetService("TeleportService")
 
local function tpPlayers(player)
	local server = tp:ReserveServer(7818885541)
 
	tp:TeleportToPrivateServer(7818885541, server, {player})
end
 
queuePart.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if not table.find(InQueue, player) then
			table.insert(InQueue, player)
			if #InQueue > 1 then
				wait(10)
				for i, v in pairs(InQueue) do
					tpPlayers(v)
					print("Teleporting.. " .. v.Name)
				end
			end
		end
	end
end)
local queuePart = game.Workspace.Queue
local InQueue = {}
local tp = game:GetService("TeleportService")

local function tpPlayers(playerQueue)
	local server = tp:ReserveServer(7818885541)
	tp:TeleportToPrivateServer(7818885541, server, playerQueue)
end

queuePart.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if not table.find(InQueue, player) then
			table.insert(InQueue, player)
			if #InQueue > 1 then
				wait(10)
				tpPlayers(InQueue)
				print("Teleporting... " .. table.concat(InQueue, ", "))
			end
		end
	end
end)
4 Likes

Ill try that ill tell u if it works thanks dude!!! :smiley:

It works perfectly as i expected!! Thanks again for the help, and thanks to everyone who helped me in this thread!!