How to create new place for teleport?

Are you touching the part when it’s saying teleporting? Okay go in roblox studio and run the game there, touch the part wait for the teleport thingy, and then send me what it says, with the table expanded

It says this:
15:43:19.795 teleporting - Server - Script:19
15:43:19.795 {} - Server - Script:20

It says it before I even touch the part.

Okay so it’s running before you even touch it, do this

Replace that with task.wait(20) or more put it how long you want it to be, as long as you are touching the part. I’ll give you a script that is working constantly and will not teleport if the table is empty:

local players = {}
local placeId = 7951878865
local Part = script.Parent 

local TeleportService = game:GetService("TeleportService")

Part.Touched:Connect(function(hit)
	pcall(function()
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if (plr:IsA("Player")) then
           table.insert(players, plr)
        end
	end)
end)

function TeleportPlayers()

print("teleporting")
print(players)

pcall(function()
if players ~= {} then
	local reservedServer = TeleportService:ReserveServer(placeId)
	TeleportService:TeleportToPrivateServer(placeId, reservedServer, players, nil, nil, nil)
end)
else
print("not enough players")
end
end

while wait() do
wait(10)
TeleportPlayers()
end

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

1 Like

This is what I made, I want to teleport the players as soon as they touch the part.

local players = {}

local placeId = 7951878865

local Part = script.Parent

local TeleportService = game:GetService(“TeleportService”)

Part.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if (plr:IsA(“Player”)) then
table.insert(players, plr)
end
print(“teleporting”)
print(players)

  local reservedServer = TeleportService:ReserveServer(placeId)
  TeleportService:TeleportToPrivateServer(placeId, reservedServer, players, nil, nil, nil)

end)

It still doesn’t work but has no errors.

If you teleport them as soon as they touch the part you will only teleport 1 player as it runs once for every player. You can make a reserved server outside the touched function and you can change it every 30 seconds or something, but you can put the reserved server outside and in the touched function put this

local reservedServer = TeleportService:ReserveServer(placeId) 

Part.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if (plr:IsA(“Player”)) then
print(“teleporting”)

TeleportService:TeleportToPrivateServer(placeId, reservedServer, { plr }, nil, nil, nil) 
end
end)


This is what I have, the boat rides into the part that teleports them (players are in the boat). I used your other script and it still doesn’t work.

This script:

local players = {}
local placeId = 7951878865
local Part = script.Parent

local TeleportService = game:GetService(“TeleportService”)

Part.Touched:Connect(function(hit)
pcall(function()
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if (plr:IsA(“Player”)) then
table.insert(players, plr)
end
end)
end)

function TeleportPlayers()
print(“teleporting”)
print(players)

pcall(function()
if players ~= {} then
local reservedServer = TeleportService:ReserveServer(placeId)
TeleportService:TeleportToPrivateServer(placeId, reservedServer, players, nil, nil, nil)

else
print(“not enough players”)
end
end)
end

while wait() do
wait(10)
TeleportPlayers()
end

The script is under the part that they are touching.

In guessing the script is in the giant blank part, if that’s the case players aren’t technically touching the part, the boat is, how you can bypass this, you can just put the script in the boat and then run the function I made after it touches the part or just wait some time and then teleport all the players that are in the boat.

Put this script in the boat

local players = {}
local waittime = 10 -- how long do you want to wait until teleport
local TeleportService = game.TeleportServjce
local placeId = 7951878865

script.Parent.Touched:Connect(function(hit)
      pcall(function()
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if player then
                   table.insert(players, player)
            end
      end)
end)

while true do
     wait(waittime)
pcall(function()
     local server = TeleportService:ReserveServer(placeId)
     TeleportService:TeleportToPrivateServer(placeId, server, players)
end)
end

One place for multiple groups of players, they will then be automatically split into different servers accordingly (which is the standard to how Roblox populates games anyway).

He’s trying to make a story game I think and wants to teleport them to a place where only they will be (a reserved server) when they enter the boat

It’s a story game entrance and then the actual game is in that reserved server, that is what I want to do.