ShoccessX

Severhop

Sep 15th, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. -- Services
  2. local HttpService = game:GetService("HttpService")
  3. local TeleportService = game:GetService("TeleportService")
  4. local Players = game:GetService("Players")
  5.  
  6. -- Configuration
  7. local placeId = game.PlaceId
  8. local maxPlayersLimit = _G.ServerPlayers or 10 -- Default to 10 if _G.ServerPlayers is not set
  9.  
  10. -- Function to hop to a different server
  11. local function serverHop()
  12. -- Fetch list of servers
  13. local url = "https://games.roblox.com/v1/games/" .. placeId .. "/servers/Public?sortOrder=Asc&limit=100"
  14. local success, response = pcall(function()
  15. return HttpService:HttpGet(url)
  16. end)
  17.  
  18. if not success then
  19. warn("Failed to fetch servers: " .. response)
  20. return
  21. end
  22.  
  23. -- Parse server data
  24. local servers = HttpService:JSONDecode(response).data
  25.  
  26. for _, server in pairs(servers) do
  27. if server.playing > maxPlayersLimit and server.playing < server.maxPlayers then
  28. -- Teleport to the found server
  29. TeleportService:TeleportToPlaceInstance(placeId, server.id)
  30. print("Teleporting to server with ID:", server.id)
  31. return
  32. end
  33. end
  34.  
  35. print("No suitable server found.")
  36. end
  37.  
  38. -- Main logic
  39. if placeId == 15297128281 then
  40. if #Players:GetPlayers() <= maxPlayersLimit then
  41. serverHop()
  42. end
  43. end
Advertisement
Add Comment
Please, Sign In to add comment