xvc200

Server Hop Script

Feb 13th, 2025 (edited)
61,354
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. local HttpService = game:GetService("HttpService")
  2. local TeleportService = game:GetService("TeleportService")
  3. local CoreGui = game:GetService("CoreGui")
  4. local StarterGui = game:GetService("StarterGui")
  5.  
  6. local RemoveErrorPrompts = true
  7. local IterationSpeed = 0.25
  8. local ExcludefullServers = true
  9. local SaveTeleportAttempts = false
  10.  
  11. local API = "https://games.roblox.com/v1/games/" .. game.PlaceId .. "/servers/Public?limit=100"
  12.  
  13. local function notify(txt)
  14. pcall(function()
  15. StarterGui:SetCore("SendNotification", {
  16. Title = "Server Hop",
  17. Text = txt,
  18. Duration = 3
  19. })
  20. end)
  21. end
  22.  
  23. local function EncodeToFile(JSONString)
  24. local success, JSONData = pcall(function()
  25. return HttpService:JSONDecode(JSONString)
  26. end)
  27.  
  28. if not success or not JSONData or not JSONData.data then
  29. return nil
  30. end
  31.  
  32. JSONData.gameId = game.PlaceId
  33.  
  34. local success2, encoded = pcall(function()
  35. return HttpService:JSONEncode(JSONData)
  36. end)
  37.  
  38. if success2 then
  39. writefile("Servers.JSON", encoded)
  40. end
  41.  
  42. return JSONData
  43. end
  44.  
  45. local function NextCursor(cursor)
  46. return game:HttpGet(API ..
  47. "&excludeFullGames=" .. tostring(ExcludefullServers) ..
  48. (cursor and "&cursor=" .. cursor or "") ..
  49. "&_=" .. tick())
  50. end
  51.  
  52. local function StartTeleport()
  53. local JSONData = EncodeToFile(readfile("Servers.JSON"))
  54.  
  55. if not JSONData then
  56. notify("Refreshing server list...")
  57. writefile("Servers.JSON", game:HttpGet(API .. "&_=" .. tick()))
  58. return StartTeleport()
  59. end
  60.  
  61. for i = #JSONData.data, 1, -1 do
  62. local server = JSONData.data[i]
  63.  
  64. if server and server.id ~= game.JobId then
  65. local JobId = server.id
  66. table.remove(JSONData.data, i)
  67.  
  68. local _, encoded = pcall(function()
  69. return HttpService:JSONEncode(JSONData)
  70. end)
  71.  
  72. if encoded then
  73. writefile("Servers.JSON", encoded)
  74. end
  75.  
  76. if SaveTeleportAttempts then
  77. appendfile("Attempts.txt", JobId .. "\n")
  78. end
  79.  
  80. notify("Trying: "..server.playing.."/"..server.maxPlayers)
  81. TeleportService:TeleportToPlaceInstance(game.PlaceId, JobId, game.Players.LocalPlayer)
  82. task.wait(IterationSpeed)
  83. end
  84. end
  85.  
  86. if JSONData.nextPageCursor then
  87. notify("Next page...")
  88. EncodeToFile(NextCursor(JSONData.nextPageCursor))
  89. StartTeleport()
  90. else
  91. notify("Restarting search...")
  92. writefile("Servers.JSON", game:HttpGet(API .. "&_=" .. tick()))
  93. StartTeleport()
  94. end
  95. end
  96.  
  97. local function SetMainPage()
  98. notify("Loading servers...")
  99. writefile("Servers.JSON", game:HttpGet(API .. "&_=" .. tick()))
  100. StartTeleport()
  101. end
  102.  
  103. if RemoveErrorPrompts then
  104. pcall(function()
  105. CoreGui:WaitForChild("RobloxGui"):WaitForChild("Modules"):WaitForChild("ErrorPrompt"):Destroy()
  106. CoreGui:WaitForChild("RobloxPromptGui"):Destroy()
  107. end)
  108. end
  109.  
  110. if isfile("Servers.JSON") then
  111. local success, JSONData = pcall(function()
  112. return HttpService:JSONDecode(readfile("Servers.JSON"))
  113. end)
  114.  
  115. if success and JSONData then
  116. if JSONData.gameId ~= game.PlaceId then
  117. notify("Game changed, resetting cache...")
  118. SetMainPage()
  119. elseif JSONData.data and #JSONData.data > 0 then
  120. StartTeleport()
  121. elseif JSONData.nextPageCursor then
  122. notify("Fetching more servers...")
  123. EncodeToFile(NextCursor(JSONData.nextPageCursor))
  124. StartTeleport()
  125. else
  126. SetMainPage()
  127. end
  128. else
  129. SetMainPage()
  130. end
  131. else
  132. SetMainPage()
  133. end
Advertisement
Comments
Add Comment
Please, Sign In to add comment