I need all players to teleport but- what?

I dont know why but it wont teleport all players… just one (when one player touches the part I want all to be transported)

local telePart = script.Parent
local TeleportService = game:GetService('TeleportService')
local placeID = (13050238945)
local canTeleport = true

local function otherGame(otherPart)

	local player = game.Players:FindFirstChild(otherPart.Parent.Name)

	if player and canTeleport then
                 
		canTeleport = false
                local ReservedServerAccessCode = TeleportService:ReserveServer(placeID)
		TeleportService:TeleportToPrivateServer(placeID, ReservedServerAccessCode, {player})

		wait(0.3) --cooldown time

		canTeleport = true

	end

end

telePart.Touched:Connect(otherGame)
3 Likes

Change this to {game.Players:GetPlayers()}, it will teleport all players in the server

I believe its because you are only checking for one player.

This is what could work (havent tested it, its only example code anyway)

local telePart = script.Parent
local TeleportService = game:GetService('TeleportService')
local placeID = (13050238945)
local canTeleport = true

local function otherGame(otherPart)

	local players = game.Players:GetPlayers()
	for _, plr in ipairs(players) do
        if not canTeleport then return end
		canTeleport = false
        local ReservedServerAccessCode = TeleportService:ReserveServer(placeID)
		TeleportService:TeleportToPrivateServer(placeID, ReservedServerAccessCode, {plr})

		task.wait(0.3) --cooldown time

		canTeleport = true
	end

end

its saying this in output " 01:27:59.082 HTTP 403 (Forbidden) - Server - Script:13"

when I test this nothing happens when I go to the door and I dont get an error output code

You can’t teleport in Studio, test it in an actual game server

I did do it in a actual server

how do I actually fix this???

its not working!

please help fix it

What is your exact issue at the moment.

simple, this script, is sending every player who touches it, into a different reserved server… but its a party based game… so I want when one player touches the part. all players in server get sent into the reserved server…

local telePart = script.Parent
local TeleportService = game:GetService('TeleportService')
local placeID = (13050238945)
local canTeleport = true

local function otherGame(otherPart)

	local player = game.Players:FindFirstChild(otherPart.Parent.Name)

	if player and canTeleport then

		canTeleport = false
		local ReservedServerAccessCode = TeleportService:ReserveServer(placeID)
		TeleportService:TeleportToPrivateServer(placeID, ReservedServerAccessCode, {player})

		wait(0.3) --cooldown time

		canTeleport = true

	end

end

telePart.Touched:Connect(otherGame)
local telePart = script.Parent
local TeleportService = game:GetService("TeleportService")
local placeID = 13050238945
local canTeleport = true

local function otherGame(otherPart)
	local player = game:GetService("Players"):GetPlayerFromCharacter(otherPart.Parent)
	if player and canTeleport then
		canTeleport = false
		for _,plr in ipairs(game:GetService("Players"):GetPlayers()) do
			local AccessCode = TeleportService:ReserveServer(placeID)
			local TeleportOptions = Instance.new("TeleportOptions")
			TeleportOptions.ReservedServerAccessCode = AccessCode
			coroutine.wrap(function()
				local Success,Error = pcall(function()
					TeleportService:TeleportAsync(placeID,{plr},TeleportOptions)
				end)
				if not Success then warn(Error) end
			end)
		end
		task.wait(0.3)
		canTeleport = true
	end
end
telePart.Touched:Connect(otherGame)

I used this and it worked
Have you made sure the game the player is inside and the teleport game are within the same universe?

TeleportService:TeleportToPrivateServer(placeID, TeleportService:ReserveServer(placeID), game.Players:GetPlayers())

idk why it didnt work again… it would give me a error if im in studio or if its no place id… but no error and im not being teleported at all

Have you tested this on the actual server? Not in Studio, but on the app itself.
If so, does it give any errors/warnings in dev console?

try this

local function otherGame(otherPart)
	if otherPart.Parent:FindFirstChild("Humanoid") then
		pcall(function()
			local players = game.Players:GetPlayers()

			if canTeleport then
				canTeleport = false

				local ReservedServerAccessCode = TeleportService:ReserveServer(placeID)
				TeleportService:TeleportToPrivateServer(placeID, ReservedServerAccessCode, players)

				task.wait(0.3) --cooldown time

				canTeleport = true
			end
		end)
	end
end

telePart.Touched:Connect(otherGame)