Teleporting a table of players to a private server

Like the GUI and everything? What would be the easiest way for me to send that to you?

  1. Save the place and upload it here.
  2. Make a public model that I can insert into a baseplate to have what you have right now

place
https://www.roblox.com/games/9499718198/Raptor-Royale

model
https://www.roblox.com/library/9529346383/stuff

Alrighty thanks I’ll give it a shot in a few minutes once I get to my computer

take your time, thank you for all of this help i really do appreciate it, also as a heads up only “Room 1” button works at this time because i haven’t coded the other buttons

1 Like

Ahhhhhhh this was all my fault, I forgot one line of code. Oops!

game.ReplicatedStorage.JoinRoom.OnServerEvent:Connect(function(player,roomName)
	local newPlayers = {}
	for _, v in ipairs(rooms[roomName].players) do
		table.insert(newPlayers, v)
	end
	table.insert(newPlayers, player)
	print(newPlayers)
	rooms[roomName].players = newPlayers
	print(player.Name.." joined "..roomName..".")
end)

Should replace:

Also try this for the teleporting:

local playerList = room.players
		local placeId = TeleportService:ReserveServer(game.PlaceId)
		local success, result = pcall(function()
			print(playerList)
			return TeleportService:TeleportToPrivateServer(game.PlaceId, placeId, playerList)
		end)
		
		print(success, result)
		for _, plr in pairs(playerList) do
			print(plr)
		end

		if success then
			local jobId = result
			print("Players teleported to "..jobId)
		else
			warn(result)
		end

only one error, “attempt to index nil with players”
at the part that says, “local playerList = room.players”

Make sure it’s still in the rest of the thing

You only wanted to replace this.

yes the error is at “local playerList = room.players”

Room shouldn’t be nil because this should still be in the script

oh my gosh im so dumb, I replaced the top half of code with the new one you gave me, im sorry.

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

local rooms = {
	Room1 = {
		players={}
	},
	Room2 = {
		players={}
	},
	Room3 = {
		players={}
	}
}
local playerList = room.players --room.players
local placeId = TeleportService:ReserveServer(game.PlaceId)
local success, result = pcall(function()
	print(playerList)
	return TeleportService:TeleportToPrivateServer(game.PlaceId, placeId, playerList)
end)

print(success, result)
for _, plr in pairs(playerList) do
	print(plr)
end

if success then
	local jobId = result
	print("Players teleported to "..jobId)
else
	warn(result)
end

game.ReplicatedStorage.JoinRoom.OnServerEvent:Connect(function(player,roomName)
	local newPlayers = {}
	for _, v in ipairs(rooms[roomName].players) do
		table.insert(newPlayers, v)
	end
	table.insert(newPlayers, player)
	print(newPlayers)
	rooms[roomName].players = newPlayers
	print(player.Name.." joined "..roomName..".")
end)

what am I missing? (sorry)


game.ReplicatedStorage.StartRoom.OnServerEvent:Connect(function(player, roomName)
	local room = rooms[roomName]
	if #room.players > 0 then
	local playerList = room.players
		local placeId = TeleportService:ReserveServer(game.PlaceId)
		local success, result = pcall(function()
			print(playerList)
			return TeleportService:TeleportToPrivateServer(game.PlaceId, placeId, playerList)
		end)
		
		print(success, result)
		for _, plr in pairs(playerList) do
			print(plr)
		end

		if success then
			local jobId = result
			print("Players teleported to "..jobId)
		else
			warn(result)
		end
	end
end)

That should be what you have for the teleporting aspect

where would the rooms tables go?

The rooms table stays at the beginning of the script.

It works! There is only one problem, lol, I get teleported to the exact same place instead of the separate place.

Try this:

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

local rooms = {
	Room1 = {
		players={},
		code=0
	},
	Room2 = {
		players={},
		code=0
	},
	Room3 = {
		players={},
		code=0
	}
}

game.ReplicatedStorage.StartRoom.OnServerEvent:Connect(function(player, roomName)
	local room = rooms[roomName]
	print(roomName.players, #room.players)
	for _, plr in pairs(room.players) do
		print(plr)
	end
	if #room.players > 0 then
		local playerList = room.players
		local placeId = TeleportService:ReserveServer(9500853800)
		local success, result = pcall(function()
			print(playerList)
			return TeleportService:TeleportToPrivateServer(game.PlaceId, placeId, playerList)
		end)
		
		print(success, result)
		for _, plr in pairs(playerList) do
			print(plr)
		end

		if success then
			local jobId = result
			print("Players teleported to "..jobId)
		else
			warn(result)
		end
	end
end)

game.ReplicatedStorage.JoinRoom.OnServerEvent:Connect(function(player,roomName)
	local newPlayers = {}
	for _, v in ipairs(rooms[roomName].players) do
		table.insert(newPlayers, v)
	end
	table.insert(newPlayers, player)
	print(newPlayers)
	rooms[roomName].players = newPlayers
	print(player.Name.." joined "..roomName..".")
end)

Note This Replaces The Whole Server Script!

Perfect, it says i couldn’t teleport because its forbidden but im guessing its because the game is not public?

I don’t know, maybe try making the game public and testing it.

hm, its back at no longer teleporting me.