How to Teleport Players in difficult Server in one Private Server?

The Playerscount in the Game is 1. All 10 Players in difficult Server have clicked “Ready”. Then they all should teleport to the Private Server. How can i make this to work?
Thanks.

Use TeleportService:ReserveServer() to get the access code then use it in TeleportService:TeleportToPrivateServer() like this:

local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")

function TeleportGroup(placeId, players)
	local accessCode = TeleportService:ReserveServer(placeId)
	
	local Success, Error = pcall(function()
		TeleportService:TeleportToPrivateServer(placeId, accessCode, players)
	end)
	
	if not Success then 
		warn(Error)
	end
	return Success
end

local players_array = Players:GetPlayers() 
local placeId = 0 

TeleportGroup(placeId, players_array)
2 Likes

But how it stops when 10 player are in the Server? How the Script know that 10 Player in Difficult Server have clicked “Ready”? Just when 10 Players have clicked Ready in a 1 Count Server they should teleport to a Private Server. And thanks for the Help!

it’s a working sample, you basically have to do that all by yourself but since i have some time i’ll give you some notes, you create a table where players are inserted in when they pressed the ready button and if they click again on the changed unready button, it removes them from the table after checking whether they were already in or not to avoid some issues

you get the numbers of the table using the symbol # which you can call a hashtag, check if #plrTable >= 10 then you initiate the teleportation process, a method to avoid instant starting when a player accidentally clicks on it is to add a timer for about 7 seconds (not too long or short)

so when the # numbering changes when someone unready’s it will cancel the timer and the teleportation process, hopefully you understood and requires some knowledge so don’t bother googling the properties and functions of gui objects in the developer hub

But the Players are all in Different Servers

You’ll need to use MemoryStoreService to store all the players who clicked ready in the party. Its similar to DataStoreService, but is better for this because its temporary data.

Can you show me a Script Example?

local TeleportService = game:GetService("TeleportService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

function TeleportGroup(placeId, players)
	local accessCode = TeleportService:ReserveServer(placeId)

	local Success, Error = pcall(function()
		TeleportService:TeleportToPrivateServer(placeId, accessCode, players)
	end)

	if not Success then 
		warn(Error)
	end
	return Success
end

--[[I assume the client sents a request to the server from a client script
inside a UI that's either true or false]]
local Remote = ReplicatedStorage:WaitForChild("Ready")

local players_array = {} 
local placeId = 0 

--avoiding to repeat code
function remove(player)
	local index = table.find(players_array, player) 
	if index then 
		table.remove(players_array, index)
	end
end

Remote.OnServerEvent:Connect(function(player, state) 
	if state then 
		if not table.find(players_array, player) then 
			table.insert(players_array, player)
		end
	else 
		remove()
	end
	task.wait(7) --suggestion from older reply
	if #players_array >= 10 then 
		TeleportGroup(placeId, players_array) 
		--no need to manually remove any players(PlayerRemoving will fire)
	end
end)

--All players inside the array must be in the current server
Players.PlayerRemoving:Connect(function(player)
	remove(player)
end)

Unfortunately I have no experience with MemoryStoreService so I can’t assist you on that.

1 Like

try TeleportAsync

You’ll likely need to make use of the MessagingService as well to allow for multiple servers to communicate with one another in order to flag that each has a player that is trying to teleport to a particular private server.

Okay thank you can i have a example?