fadhil_297

Autosave Recovery Map

Jul 26th, 2025
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.58 KB | Source Code | 0 0
  1. --[[
  2.     Change the time for the last time the map existed. Use GMT 0 to
  3. ]]
  4. local time = DateTime.fromUniversalTime(2025, 7, 26, 3, 36)
  5. local DataStoreService = game:GetService("DataStoreService")
  6.  
  7. -- Helper function to safely disable the autosave script
  8. local function disableAutosave()
  9.     local autosaveFolder = game:GetService("ServerScriptService")["april 13"]
  10.     if autosaveFolder then
  11.         -- Look for any scripts inside the folder that might be responsible for autosaving
  12.         for _, child in ipairs(autosaveFolder:GetChildren()) do
  13.             if child:IsA("Script") or child:IsA("ModuleScript") then
  14.                 child:Destroy()
  15.                 print("Disabled autosave script: " .. child:GetFullName())
  16.             end
  17.         end
  18.         print("All autosave scripts in 'autosave v5 fix 2' have been disabled.")
  19.     else
  20.         warn("Autosave folder 'autosave v5 fix 2' not found")
  21.     end
  22. end
  23.  
  24. -- First recover the metadata to know how many chunks we need to recover
  25. local metadataStore = DataStoreService:GetDataStore("GlobalMapStore_Meta")
  26. local listSuccess, metaPages = pcall(function()
  27.     return metadataStore:ListVersionsAsync("MapMetadata", nil, time.UnixTimestampMillis)
  28. end)
  29.  
  30. if listSuccess then
  31.     local metaItems = metaPages:GetCurrentPage()
  32.     if #metaItems > 0 then
  33.         local metaVersion = metaItems[1].Version
  34.         local success, metadata
  35.         success, metadata = pcall(function()
  36.             return metadataStore:GetVersionAsync("MapMetadata", metaVersion)
  37.         end)
  38.         if success and metadata then
  39.             print("Found map metadata from " .. os.date("%Y-%m-%d %H:%M:%S", metadata.lastSaveTime))
  40.             print("Total chunks: " .. metadata.totalChunks)
  41.             -- Restore the metadata first
  42.             metadataStore:SetAsync("MapMetadata", metadata)
  43.             -- Now restore each chunk from each datastore
  44.             local totalChunks = metadata.totalChunks
  45.             local chunksRestored = 0
  46.             local datastoreIndex = 1
  47.             while datastoreIndex <= 200 and chunksRestored < totalChunks do
  48.                 local currentStore = DataStoreService:GetDataStore("GlobalMapStore" .. datastoreIndex)
  49.                 for i = 1, math.min(5, totalChunks - chunksRestored) do
  50.                     local chunkIndex = chunksRestored + 1
  51.                     if chunkIndex > totalChunks then break end
  52.                     local chunkKey = "GlobalMap_Chunk" .. chunkIndex
  53.                     local listSuccess, chunkPages = pcall(function()
  54.                         return currentStore:ListVersionsAsync(chunkKey, nil, time.UnixTimestampMillis)
  55.                     end)
  56.                     if listSuccess then
  57.                         local chunkItems = chunkPages:GetCurrentPage()
  58.                         if #chunkItems > 0 then
  59.                             local chunkVersion = chunkItems[1].Version
  60.                             local chunkSuccess, chunkData
  61.                             chunkSuccess, chunkData = pcall(function()
  62.                                 return currentStore:GetVersionAsync(chunkKey, chunkVersion)
  63.                             end)
  64.                             if chunkSuccess and chunkData then
  65.                                 currentStore:SetAsync(chunkKey, chunkData)
  66.                                 print("Restored chunk " .. chunkIndex .. " from GlobalMapStore" .. datastoreIndex)
  67.                                 chunksRestored = chunksRestored + 1
  68.                             else
  69.                                 warn("Failed to restore chunk " .. chunkIndex)
  70.                             end
  71.                         else
  72.                             warn("No version found for chunk " .. chunkIndex)
  73.                         end
  74.                     else
  75.                         warn("Failed to list versions for chunk " .. chunkIndex)
  76.                     end
  77.                 end
  78.                 datastoreIndex = datastoreIndex + 1
  79.             end
  80.             print("Map restoration complete! Restored " .. chunksRestored .. " of " .. totalChunks .. " chunks.")
  81.             print("Restart the server to load the recovered map.")
  82.         else
  83.             warn("Failed to retrieve metadata version")
  84.         end
  85.     else
  86.         warn("No metadata versions found before the specified time")
  87.     end
  88. else
  89.     warn("Failed to list metadata versions")
  90. end
  91.  
  92. -- Disable the autosave script after recovery
  93. disableAutosave()
Tags: recovermap
Advertisement
Add Comment
Please, Sign In to add comment