Teleportation should always be in the same Server

Do you put a line that returns all players in your server?
local Players = game:GetService("Players")
local players = Players:GetPlayers() -- Get a list of all players

should it be a server script in server script storage

Yes, since it uses players, you won’t have any local player stuff etc

oh I know why cause the players didnt get detected it detects too fast I must put a wait

Oops, both the variables have the same name :sweat_smile:

Try this:
local PlayerService = game:GetService("Players")
local Players = PlayerService:GetPlayers() -- Get a list of all players

It doesnt work quite right if a server is full a new server gets created I dont want that

You can’t really make an unlimited server, roblox limits it.
Eitherway, it’ll lag the server so making an unlimited server is not what you always will wanna do

nonono I mean the size should be 50 players but when somebody tries to join while 50 players are playing it should say GAME FULL WAITING and not create a new one

It shouldn’t create a new one, it’ll send players to the same server using the code/servercode parameter

this is the script Im using rn

wait(2.5)
local placeId = 6993413889
local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")

local code = TS:ReserveServer(placeId) -- Returns a code
local players = Players:GetPlayers() -- Get a list of all players

TS:TeleportToPrivateServer(placeId,code,players) -- Actually teleport the players
-- You could add extra arguments to this function: spawnName, teleportData and customLoadingScreen

It should really only send them to the ā€œcodeā€ reserved server, I don’t know why it’s doing that… maybe, a roblox thing…?

btw I have set the server limit to 1 to test it out and came with 2 accounts it created 2 servers

I’m not so sure, tbh.
Try setting your server fill to maximum:

It is already so I cant really change nothing

Ahh… I will assume there’s no way to not create a new server when a game is full, i think roblox does that in their engine/core

But some games do that like ERLC they have a private server section with SERVER1 to 3 or so and custom servers

I found out that it always returns a new code and not the same when I always type the code ā€œSERVERā€ it gives an error

You have to edit the variable name from code to server

WORKS!

wait(5)
local placeId = 6993413889
local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")
local players = Players:GetPlayers() -- Get a list of all players
local DSS = game:GetService("DataStoreService")
local DS = DSS:GetGlobalDataStore()
local code = DS:GetAsync("ReservedServer")
print(code)
if type(code) ~= "string" then -- None saved, create one
	code = TS:ReserveServer(placeId)
	DS:SetAsync("ReservedServer",code)
	print("Create")
else
	print("Use")
end

print(code)
TS:TeleportToPrivateServer(placeId,code,players) -- Actually teleport the players
-- You could add extra arguments to this function: spawnName, teleportData and customLoadingScreen
1 Like