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