Alex_Scripter13

wow

Oct 28th, 2024
3,013
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. local HTTPService = game:GetService("HttpService")
  2. local TeleportService = game:GetService("TeleportService")
  3. local StatsService = game:GetService("Stats")
  4.  
  5. local function fetchServersData(placeId, limit)
  6. local url = string.format("https://games.roblox.com/v1/games/%d/servers/Public?limit=%d", placeId, limit)
  7. local success, response = pcall(function()
  8. return HTTPService:JSONDecode(game:HttpGet(url))
  9. end)
  10.  
  11. if success and response and response.data then
  12. return response.data
  13. end
  14.  
  15. return nil
  16. end
  17.  
  18. local placeId = game.PlaceId
  19. local serverLimit = 100
  20. local servers = fetchServersData(placeId, serverLimit)
  21.  
  22. if not servers then
  23. return
  24. end
  25.  
  26. local lowestPingServer = servers[1]
  27.  
  28. for _, server in pairs(servers) do
  29. if server["ping"] < lowestPingServer["ping"] and server.maxPlayers > server.playing then
  30. lowestPingServer = server
  31. end
  32. end
  33.  
  34. local commonLoadTime = 5
  35. task.wait(commonLoadTime)
  36.  
  37. local pingThreshold = 100
  38. local serverStats = StatsService.Network.ServerStatsItem
  39. local dataPing = serverStats["Data Ping"]:GetValueString()
  40. local pingValue = tonumber(dataPing:match("(%d+)"))
  41.  
  42. if pingValue >= pingThreshold then
  43. TeleportService:TeleportToPlaceInstance(placeId, lowestPingServer.id)
  44. else
  45. -- Good ping
  46. end
Add Comment
Please, Sign In to add comment