How can you make a system where you can create a room, with a private code, and players can join?

I know how to do the Teleportation part. I can do creating the room, but I really don’t know where to start with the code. I’m not experienced in this type of stuff, basically I want to make something like Apeirophobia’s lobby system.

I am not asking for full-on code, but an idea on how to start/do it.

You can use a module of all the rooms like this

local Rooms = {
	["Gameg`s room"] = {
		["InQueue"] = {
			game.Players.Gameg
		},

		["Code"] = "68AD2631-CA94-49FD-AD29-EA25D94493AD" -- can be set to nil
	}
}

return Rooms 

And then since its a table you can teleport all of them using this module

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

local ATTEMPT_LIMIT = 5
local RETRY_DELAY = 1
local FLOOD_DELAY = 15

local function SafeTeleport(placeId, players, options)
    local attemptIndex = 0
    local success, result -- define pcall results outside of loop so results can be reported later on

    repeat
        success, result = pcall(function()
            return TeleportService:TeleportAsync(placeId, players, options) -- teleport the user in a protected call to prevent erroring
        end)
        attemptIndex += 1
        if not success then
            task.wait(RETRY_DELAY)
        end
    until success or attemptIndex == ATTEMPT_LIMIT -- stop trying to teleport if call was successful, or if retry limit has been reached

    if not success then
        warn(result) -- print the failure reason to output
    end

    return success, result
end

local function handleFailedTeleport(player, teleportResult, errorMessage, targetPlaceId, teleportOptions)
    if teleportResult == Enum.TeleportResult.Flooded then
        task.wait(FLOOD_DELAY)
    elseif teleportResult == Enum.TeleportResult.Failure then
        task.wait(RETRY_DELAY)
    else
        -- if the teleport is invalid, report the error instead of retrying
        error(("Invalid teleport [%s]: %s"):format(teleportResult.Name, errorMessage))
    end

    SafeTeleport(targetPlaceId, {player}, teleportOptions)
end

TeleportService.TeleportInitFailed:Connect(handleFailedTeleport)

return SafeTeleport

and use it like this

local TeleportService = game:GetService("TeleportService")
local SafeTeleport = require(script.Teleport)
local Rooms = require(script.Rooms)

local PlaceId = 1
local BackupServer = TeleportService:ReserveServer(PlaceId)
local Options = Instance.new("TeleportOptions")
Options.ReservedServerAccessCode = BackupServer

local RoomToTeleport = "Gameg`s room"

SafeTeleport(PlaceId, Rooms[RoomToTeleport].InQueue, Options)
Rooms[RoomToTeleport] = nil
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.