How to add a custom 5 digit player code instead of the randomly generated one from TeleportService:ReserveServer()?


local isReserved = game.PrivateServerId ~= "" and game.PrivateServerOwnerId == 0
local DSS = game:GetService("DataStoreService")
local DS = DSS:GetGlobalDataStore()
local TS = game:GetService("TeleportService")
local players = game:GetService("Players")
local Code = DS:GetAsync("ReservedServer")

if type (Code) ~= "string" then
	Code = TS:ReserveServer(game.PlaceId)
	DS:SetAsync("ReservedServer", Code)
end

local remoteEvent = game.ReplicatedStorage.TPPlayer

remoteEvent.OnServerEvent:Connect(function(player, code)
	
	if code == Code then
		TS:TeleportToPrivateServer(game.PlaceId,code,{player})
	end
	
end)

print(Code)





Use GlobalDataStore | Roblox Creator Documentation

Write up a custom code, save it to the Global Datastore along with the actual code. When you want to retrieve it, you can do so with the custom code.