Categories > Coding > Lua >

Roblox Server Hop Logic - Help Needed

New Reply

Posts: 1

Threads: 1

Joined: Dec, 2025

Reputation: 0

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

  • 0

  • Comment

_realnickk

Security Researcher

moderator

Posts: 95

Threads: 2

Joined: Feb, 2020

Reputation: 86

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.

  • 0

  • Comment

Security researcher, low-level programmer, and system administrator.

https://github.com/reversed-coffee

Login to unlock the reply editor

Add your reply

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )