repeat task.wait() until game.Players.LocalPlayer and  game.Players.LocalPlayer:FindFirstChild("PlayerGui") and game.Players.LocalPlayer.PlayerGui:FindFirstChild("Main") and  game.Players.LocalPlayer.PlayerGui.Main:FindFirstChild("ChooseTeam")

local HS = game:GetService("HttpService")
local lp = game.Players.LocalPlayer
local rs = game:GetService("ReplicatedStorage")
local ts = game:GetService("TeleportService")

coroutine.wrap(function()
local prompt = assert(game:GetService("CoreGui"):FindFirstChild("promptOverlay", true))
prompt.ChildAdded:Connect(function(child)
   assert(child, typeof(child) == "Instance" and child.Name == "ErrorPrompt" and child.ClassName == "Frame" and game:GetService("RunService").RenderStepped:Connect(function()
    ts:Teleport(game.PlaceId)
end))
end)
end)()

if lp.Character:FindFirstChild("HumanoidRootPart") then
rs.Remotes.CommF_:InvokeServer("SetTeam", "Pirates")
task.wait()
coroutine.wrap(function()
while task.wait() do
pcall(function()
lp.Character.HumanoidRootPart.CFrame = lp.Character.HumanoidRootPart.CFrame * CFrame.Angles(0, math.rad(120), 0)
end)
end
end)()
task.wait(0.1)
for i, v in pairs(workspace:GetDescendants()) do
    if v.Name:find("Chest") and v:IsA("Part") and v.Parent == workspace and v:FindFirstChild("TouchInterest") then
        for i = 1, 32 do
        pcall(function()
        lp.Character.HumanoidRootPart.Position = v.Position
        firetouchinterest(v:FindFirstChild("TouchInterest"))
        lp.Character.HumanoidRootPart.CFrame = lp.Character.HumanoidRootPart.CFrame * CFrame.Angles(0, math.rad(80), 0)
        end)
        task.wait(0.017)
        end
        task.wait(0.1)
    end
end
task.wait()
local a = HS:JSONDecode(game:HttpGet("https://games.roblox.com/v1/games/"..game.PlaceId.."/servers/Public?sortOrder=Asc&limit=100"))
local b = HS:JSONDecode(game:HttpGet("https://games.roblox.com/v1/games/"..game.PlaceId.."/servers/Public?sortOrder=Asc&limit=100&cursor="..a.nextPageCursor))
local c = HS:JSONDecode(game:HttpGet("https://games.roblox.com/v1/games/"..game.PlaceId.."/servers/Public?sortOrder=Asc&limit=100&cursor="..b.nextPageCursor))
local d = HS:JSONDecode(game:HttpGet("https://games.roblox.com/v1/games/"..game.PlaceId.."/servers/Public?sortOrder=Asc&limit=100&cursor="..c.nextPageCursor))
local e = HS:JSONDecode(game:HttpGet("https://games.roblox.com/v1/games/"..game.PlaceId.."/servers/Public?sortOrder=Asc&limit=100&cursor="..d.nextPageCursor))

local function ServerHop()
    table.sort(e.data, function (a, b) return a.playing < b.playing end)
    for i,v in pairs(e.data) do
        if v.maxPlayers > v.playing and v.id ~= game.JobId then
        ts:TeleportToPlaceInstance(game.PlaceId, v.id)
        end
    end
end
while task.wait(0.1) do
    ServerHop()
end
elseif not lp.Character:FindFirstChild("HumanoidRootPart") then
    lp.Character:WaitForChild("HumanoidRootPart")
    task.wait(0.1)
    rs.Remotes.CommF_:InvokeServer("SetTeam", "Pirates")
task.wait(0.2)
coroutine.wrap(function()
while task.wait() do
pcall(function()
lp.Character.HumanoidRootPart.CFrame = lp.Character.HumanoidRootPart.CFrame * CFrame.Angles(0, math.rad(120), 0)
end)
end
end)()
for i, v in pairs(game:GetService("Workspace"):GetDescendants()) do
    if v.Name:find("Chest") and v:IsA("Part") and v.Parent == game:GetService("Workspace") and v:FindFirstChild("TouchInterest") then
        for i = 1, 10 do
        pcall(function()
        lp.Character.HumanoidRootPart.Position = v.Position
        firetouchinterest(v:FindFirstChild("TouchInterest"))
        lp.Character.HumanoidRootPart.CFrame = lp.Character.HumanoidRootPart.CFrame * CFrame.Angles(0, math.rad(180), 0)
        end)
        task.wait(0.011)
        end
        task.wait(0.3)
    end
end
task.wait()
local a = game:GetService("HttpService"):JSONDecode(game:HttpGet("https://games.roblox.com/v1/games/"..game.PlaceId.."/servers/Public?sortOrder=Asc&limit=100"))
local b = game:GetService("HttpService"):JSONDecode(game:HttpGet("https://games.roblox.com/v1/games/"..game.PlaceId.."/servers/Public?sortOrder=Asc&limit=100&cursor="..a.nextPageCursor))
local c = game:GetService("HttpService"):JSONDecode(game:HttpGet("https://games.roblox.com/v1/games/"..game.PlaceId.."/servers/Public?sortOrder=Asc&limit=100&cursor="..b.nextPageCursor))
local d = game:GetService("HttpService"):JSONDecode(game:HttpGet("https://games.roblox.com/v1/games/"..game.PlaceId.."/servers/Public?sortOrder=Asc&limit=100&cursor="..c.nextPageCursor))
local e = game:GetService("HttpService"):JSONDecode(game:HttpGet("https://games.roblox.com/v1/games/"..game.PlaceId.."/servers/Public?sortOrder=Asc&limit=100&cursor="..d.nextPageCursor))

local function ServerHop()
    table.sort(e.data, function (a, b) return a.playing < b.playing end)
    for i,v in pairs(e.data) do
        if v.maxPlayers > v.playing and v.id ~= game.JobId then
        ts:TeleportToPlaceInstance(game.PlaceId, v.id)
        end
    end
end
while task.wait(0.1) do
    ServerHop()
end
end