Teleporting player to different PlaceID for same game

Hello all, I am assisting my friend Declanitory in making a horror game. I have scripted server rooms kind of like story games where you enter the room with xyz amount of players to create a separate server for them to play the story game. Though my code isn’t working. It’s popping up with an error “HTTP 400 (Bad Request)”. HTTP requests and 3rd party teleports are enabled. Here is my code.

function GenerateCode()
	local Code = math.floor(math.random(1000000,1000000000))

	if table.find(TakenCodes, Code) then
		task.wait()
		GenerateCode()
	else
		table.insert(TakenCodes, Code)
		return Code
	end
end

function Teleport(Room)
	if Room.Configuration.CurrentPlayers.Value <= 0 then return end

	local Attempts = 0
	local Success, Result
	local RandomizedCode = GenerateCode()
	local Config = Room:WaitForChild('Configuration')
	local WaitTime = Config.WaitTime
	local TimeLeft = Config.TimeLeft
	local MaxPlayers = Config.MaxPlayers
	local TeleportID = Config.TeleportID
	local CurrentPlayers = Config.CurrentPlayers

	local PlayersToTeleport = {}

	local TeleportOptions = Instance.new('TeleportOptions'); TeleportOptions.ShouldReserveServer = true; TeleportOptions.ReservedServerAccessCode = RandomizedCode

	for _, Player in pairs(Players:GetPlayers()) do
		if Player:GetAttribute('QueueRoom') == Room.Name then
			table.insert(PlayersToTeleport, Player)
		end
	end

	repeat
		Success, Result = pcall(function()
			return TeleportService:TeleportAsync(TeleportID, PlayersToTeleport, TeleportOptions)
		end)
		Attempts = Attempts + 1
		task.wait(0.5)
	until Success or Attempts >= 5

	if not Success then error('Unable to teleport to place: ' .. Room.Name) end
	
	for _, Player in pairs(Players:GetPlayers()) do
		if Player:GetAttribute('QueueRoom') == Room.Name or table.find(PlayersToTeleport, Player) then
			Player:SetAttribute('QueueRoom', 'nil')
			Player:LoadCharacter()
		end
	end

	CurrentPlayers.Value = 0
	TimeLeft.Value = WaitTime.Value
	Room.Sign.Players.Enabled = false
	Room.Sign.Countdown.Enabled = false
	Room.Sign.Countdown.Label.Text = ConvertTime(WaitTime.Value)
	Room.Sign.Players.Label.Text = CurrentPlayers.Value .. '/' .. MaxPlayers.Value
end
1 Like
local TeleportOptions = Instance.new('TeleportOptions')
TeleportOptions.ShouldReserveServer = true
TeleportOptions.ReservedServerAccessCode = tostring(RandomizedCode) 

--

repeat
    Success, Result = pcall(function()
        return TeleportService:TeleportAsync(TeleportID, PlayersToTeleport, TeleportOptions)
    end)
    Attempts = Attempts + 1
    task.wait(0.5)
until Success or Attempts >= 5

1 Like

you can also just use this model if you want a queueing system

https://www.youtube.com/watch?v=gNlV0vIjEkQ

(Make sure to get the model in the desc so you dont waste time)

1 Like

I found out why it was breaking, it was cuz it’s supposed to be TeleportID.Value. Also why would I tostring a numbervalue :face_with_raised_eyebrow:

TeleportOptions expects a string, just making sure …(more of a forced to note)