How would I teleport all players in a server to a different game

How would I get all the players in a server and teleport them to a different game but have the same exact players in (game1’s) server in this game they are teleporting to (game2). I have looked on youtube and the wiki they didn’t work. I tried :TeleportPartyAsync and reserve server also I did TeleportToPrivateServer

2 Likes

I suggest doing it like this.

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

ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(GameId)
 for _, Players in pairs(Players:GetPlayers())
  TeleportService:Teleport(GameId, Players)
 end
end)
-- Server Script, here it grabs the remote. It will teleport all players into the game from the game Id.

Now, let’s do the client.

local Button = script.Parent:WaitForChild("TextButton")
local TextBox = script.Parent:WaitForChild("TextBox")

Button.MouseButton1Click:Connect(function()
 if TextBox.Text ~= "" then
  game.ReplicatedStorage.RemoteEvent:FireServer(TextBox.Text)
 end
end)
-- Client Script, here we are getting the textbox info from text and making sure it's not empty, now it will only teleport if the game id EXISTS. We fire the remote to get the teleportation set up. and Using a button to verify it :)

Hope this makes sense, find more info here.

For now enjoy! :wink:

2 Likes

… that’s like every tutorial i see on yt I want it to be automatically because I am making a story game…

you forgot to put do after the for loop.

for _, Players in pairs(Players:GetPlayers()) do
    TeleportService:Teleport(GameId, Players)
 end

and, Players is already a thing, so the loop it should be:

for _, player in pairs(Players:GetPlayers()) do
    TeleportService:Teleport(GameId, player)
 end

oh my bad sorry I didn’t program it on roblox (:P)

You can just do

local Players = game:GetService("Players")
local GameId = 0

while wait(20 --[[to clarify this is the waiting for every SECOND.]]) do
 for _, Players in pairs(Players:GetPlayers()) do
  TeleportService:Teleport(GameId, Players)
 end
end

Can you make it so that no one can join the server after all the players have been tped to it and create a new server instead? Because I don’t want people coming in from the game and when they get teleported the game is already half way threw the story.

You’ll need to first create a reserved server, which as its name suggests is a server reserved for use by intended players only. Then when the time comes you’ll need to use “TeleportToPrivateServer()” to teleport the list of intended players to that previously created reserved server.

https://developer.roblox.com/en-us/api-reference/function/TeleportService/ReserveServer
https://developer.roblox.com/en-us/api-reference/function/TeleportService/TeleportToPrivateServer

local Players = game:GetService("Players")
local GameId = 0

local Teleported = false

while wait(20 --[[to clarify this is the waiting for every SECOND.]]) do
 for _, Players in pairs(Players:GetPlayers()) do
  TeleportService:Teleport(GameId, Players)
 end
 Teleported = true
end

Players.PlayerAdded:Connect(function(Player)
 if Teleported then
  Player:Kick("Sorry people are not ingame anymore!")
 end
end)

If that’s what you’re going for but I recommended Forummer’s idea :wink:

I mean that script didn’t change anything and the the links of the developer learning page I get that script in my game then I get a error: TeleportService:TeleportToPrivateServer must be passed an array of players which I don’t understand.

Most of my code isn’t correctly working because I didn’t reserve it to the Private Owner, there is camping tutorials able to help tho.