Greetings, I am trying to make a horror game and have issues with the teleporting script.
The issue is when teleporting I receive a bad request (HTTP 400) from line 23.
I have tried searching for multiple posts to fix that problem, but nothing helped me sop far.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you! If you have any idea what seems to be the problem please let me know!
local lobby = {}
local player = 0
local countdown = 20
local CountdownActive = false
local PlaceID = 2659399741
local DataStoreService = game:GetService("DataStoreService")
local TeleportService = game:GetService("TeleportService")
local ServerAccessCodes = DataStoreService:GetDataStore("ReservedServerAccessCodes")
local function teleport()
if #lobby > 0 then
local playersToTeleport = {}
for i=1, #lobby do
if game.Players:FindFirstChild(lobby[i]) then
table.insert(playersToTeleport, game.Players:FindFirstChild(lobby[1]))
else
table.remove(lobby, i)
end
end
local code = TeleportService:ReserveServer(PlaceID)
TeleportService:TeleportToPrivateServer(PlaceID, code, playersToTeleport)
repeat wait() until #lobby <= 0
end
end
function AddPlayer(plr)
table.insert(lobby, plr.Name)
end
function RemovePlayer(plr)
table.remove(lobby, plr.Name)
end
local SurfaceGUI = script.Parent.CountdownPart.SurfaceGui
local Frame = SurfaceGUI.Frame
local TextLabel = Frame.TextLabel
local IsTeleporting = false
if IsTeleporting == true then
while true do
TextLabel.Text = "Teleporting players"
wait(1)
TextLabel.Text = "Teleporting players."
wait(1)
TextLabel.Text = "Teleporting players.."
wait(1)
TextLabel.Text = "Teleporting players..."
wait(1)
end
end
local function Queque()
while true do
if CountdownActive == true then
if player == 0 then
CountdownActive = false
countdown = 20
else
if countdown >= 1 then
countdown = countdown-1
TextLabel.Text = countdown
elseif countdown == 0 then
IsTeleporting = true
teleport(lobby)
wait(10)
TextLabel.Text = "Waiting for players!"
CountdownActive = false
IsTeleporting = false
countdown = 20
end
end
end
wait(1)
end
end
script.Parent.Touched:Connect(function(TouchPart)
if TouchPart.Parent:WaitForChild("Humanoid") and TouchPart.Name == "Torso" then
if player <= 2 then
local Plr = game.Players:GetPlayerFromCharacter(TouchPart.Parent)
Plr.PlayerGui.LobbyGUI.Enabled = true
Plr.Character.Torso.CFrame = script.Parent.TeleportPart.CFrame
AddPlayer(Plr)
player = player+1
if CountdownActive == false then
CountdownActive = true
Queque()
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(Plyr)
for i, v in pairs(lobby) do
if v == Plyr.Name then
RemovePlayer(Plyr.Name)
player = player-1
end
end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("LeaveLobby")
Event.OnServerEvent:Connect(function(plyr)
for i, v in pairs(lobby) do
if v.Name == plyr then
RemovePlayer(plyr)
player = player-1
plyr:LoadCharacter()
end
end
end)