Teleport All Players in a game

Hello Developers,

I am trying to make a GUI where a player can input a GameId and then when they click a button it will teleport all the players to the selected GameId. Here is my script and examples.

LOCAL SCRIPT IN STARTERGUI WITH A BUTTON AS ITS PARENT

--// SERVICES
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")

--// VARIABLES
local GameId = script.Parent.Parent.Id.GameId.Text
local Value = script.Parent.Value
local PlayerList = Players:GetPlayers()

script.Parent.Activated:Connect(function()
    Value.Value = GameId
	if Value.Value > 0 then
		TeleportService:TeleportPartyAsync(GameId, PlayerList)
	end
end)

I am not getting any errors in the console.

Does anyone know how I can fix this?

2 Likes

Woops! Looks like this API is recommended with a pcall()! Also you cannot do it from a client, it requires you to interact with the server in order to fire the function. It would be too exploitable if clients were able to move other players against their will. :slight_smile:

Other points

  • Converting local GameId = script.Parent.Parent.Id.GameId.Text into local GameId = tonumberscript.Parent.Parent.Id.GameId.Text) and ditching Value, would save some lines, but won’t do much than vanity.
1 Like