Advertisement
Zynee

Untitled

Apr 8th, 2025
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 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.             TeleportService:TeleportToPlaceInstance(placeId, lowestPingServer.id)
  35.       end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement