Categories > Coding > Lua >
Roblox Server Hop Logic - Help Needed
Posted
Can anyone direct me on the code needed to make a successful auto server hop for Roblox?
I have 4 alt accounts on a different pc and they all keep joining the same lobbies despite multiple attempts to change the code to stop this from happening. Any help would be most appreciated.. Here is my code below: -
-- ===== SERVER HOPPING WITH PROPER CACHE CLEARING =====
local function getFreshServer()
local currentId = game.JobId
local placeId = game.PlaceId
-- Clean old visited servers (older than 5 minutes)
local now = os.time()
local cleanedCount = 0
for id, time in pairs(visitedServers) do
if now - time > 300 then -- 5 minutes
visitedServers[id] = nil
cleanedCount = cleanedCount + 1
end
end
if cleanedCount > 0 then
print("๐งน Cleaned " .. cleanedCount .. " old servers from long-term memory")
end
print("๐ก Finding fresh server...")
print("๐ Avoiding " .. #sessionServers .. " recent servers in session cache")
local url = "https://games.roblox.com/v1/games/" .. placeId .. "/servers/Public?sortOrder=Asc&limit=100"
local response
if syn and syn.request then
response = syn.request({Url = url, Method = "GET"})
elseif http_request then
response = http_request({Url = url, Method = "GET"})
end
if not response or response.StatusCode ~= 200 then
print("โ Failed to fetch servers")
return nil
end
local data = HttpService:JSONDecode(response.Body)
if not data or not data.data then return nil end
local freshServers = {}
local totalServers = 0
local skippedSession = 0
local skippedVisited = 0
for _, server in ipairs(data.data) do
if server and server.id then
totalServers = totalServers + 1
local serverId = tostring(server.id)
-- Skip if in current session cache
local inSessionCache = false
for _, sessionId in ipairs(sessionServers) do
if sessionId == serverId then
inSessionCache = true
skippedSession = skippedSession + 1
break
end
end
-- Skip if visited long-term
local alreadyVisited = visitedServers[serverId] ~= nil
if inSessionCache or alreadyVisited or serverId == currentId then
if alreadyVisited and not inSessionCache then
skippedVisited = skippedVisited + 1
end
continue
end
local playing = tonumber(server.playing) or 0
local maxPlayers = tonumber(server.maxPlayers) or 0
if playing > 0 and playing < maxPlayers then
table.insert(freshServers, {
id = serverId,
playing = playing,
maxPlayers = maxPlayers
})
end
end
end
print("๐ Found " .. #freshServers .. " fresh servers out of " .. totalServers .. " total")
print("๐ซ Skipped " .. skippedSession .. " session-cached servers")
print("๐ซ Skipped " .. skippedVisited .. " long-term visited servers")
if #freshServers == 0 then
print("๐ญ No fresh servers")
-- If no fresh servers, clear session cache to allow revisiting
print("๐ Clearing session cache to allow revisiting servers...")
sessionServers = {}
Settings.sessionServers = sessionServers
return nil
end
local selected = freshServers[math.random(1, #freshServers)]
print("๐ฏ Selected: " .. selected.id:sub(1, 8) .. " (" .. selected.playing .. "/" .. selected.maxPlayers .. ")")
return selected
end
local function performHop()
if Settings.isHopping then
print("โ Already hopping, skipping...")
return false
end
Settings.isHopping = true
print("\n" .. string.rep("=", 60))
print("๐ PERFORMING SERVER HOP")
print(string.rep("=", 60))
local targetServer = getFreshServer()
if not targetServer then
print("๐ No fresh servers, clearing all caches...")
visitedServers = {}
Settings.visitedServers = visitedServers
sessionServers = {}
Settings.sessionServers = sessionServers
visitedServers[game.JobId] = os.time()
print("๐ฒ Random teleport...")
local success = pcall(function()
TeleportService:Teleport(game.PlaceId)
end)
if not success then
print("โ Random teleport failed")
Settings.isHopping = false
return false
end
else
print("๐ Teleporting to: " .. targetServer.id:sub(1, 8))
visitedServers[targetServer.id] = os.time()
-- ADD TO SESSION CACHE BEFORE TELEPORTING
table.insert(sessionServers, targetServer.id)
if #sessionServers > 5 then
table.remove(sessionServers, 1)
end
-- CLEAR SESSION CACHE IMMEDIATELY AFTER ADDING (FOR NEXT SEARCH)
print("๐งน Clearing session cache for next search...")
sessionServers = {}
Settings.sessionServers = sessionServers
local success = pcall(function()
TeleportService:TeleportToPlaceInstance(game.PlaceId, targetServer.id, Players.LocalPlayer)
end)
if not success then
print("โ Teleport failed, random...")
pcall(function()
TeleportService:Teleport(game.PlaceId)
end)
end
end
Settings.stats.hops = Settings.stats.hops + 1
print("โ
Hop completed! Session cache cleared for next search.")
print(string.rep("=", 60))
Settings.isHopping = false
return true
end
-- ===== AUTO-HOP LOOP =====
local autoHopThread = nil
local function startAutoHopLoop()
if autoHopThread then
task.cancel(autoHopThread)
end
if not Settings.enabled then
Settings.enabled = true
end
print("๐ STARTING AUTO-HOP LOOP")
print("โฐ Will hop every 6 seconds")
print("๐ Session cache clears after EACH search")
autoHopThread = task.spawn(function()
while Settings.enabled do
-- Wait 6 seconds
print("\nโณ Waiting 6 seconds before hopping...")
for i = 6, 1, -1 do
if not Settings.enabled then break end
wait(1)
end
if not Settings.enabled then break end
-- Perform hop (which clears session cache)
performHop()
-- After teleport, script restarts in new server
end
print("๐ Auto-hop loop ended")
autoHopThread = nil
end)
end
local function stopAutoHop()
print("๐ STOPPING AUTO-HOP...")
Settings.enabled = false
if autoHopThread then
task.cancel(autoHopThread)
autoHopThread = nil
end
Settings.isHopping = false
print("โ
Auto-hop stopped")
end
local function startAutoHop()
if Settings.enabled then
print("โ Auto-hop already running")
return
end
Settings.enabled = true
print("โถ MANUALLY STARTING AUTO-HOP")
startAutoHopLoop()
end
Replied
You have to track visited places per account through a non-volatile store. Right now, you're using tables. When you teleport, that running script stops. The table gets wiped, and there's no way to share who visited what server because there's no shared container.
Use the filesystem or make an API to track visited servers across multiple clients. Be mindful of potential race conditions.
Cancel
Post
Security researcher, low-level programmer, and system administrator.
https://github.com/reversed-coffee
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )
Cancel
Post