--[[ made by real_redz opensource, anyone can edit the code ]] if MAIN_THREAD then --[[task.cancel(MAIN_THREAD)]] return end if not game.IsLoaded then game.Loaded:Wait() end local replicatedStorage = game:GetService("ReplicatedStorage") local players = game:GetService("Players") local localPlayer = players.LocalPlayer local libraryGenres = workspace.Library.Genres local libraryBooks = workspace.Library.Books local exitDoor = workspace.ExitDoor local bookController = require(localPlayer.PlayerScripts.Client.Runtime.BookController) local enum = require(replicatedStorage.Shared.Utility.Enum) local userLibraryData = bookController.Replica.Data.Players[localPlayer.Name] local BOOKS_SECTION = {} local BOOKS_GENRES = {} local booksGenres = enum.Genres local function grabBook(book: Instance): (nil) bookController.Replica:FireServer("Grab", book) end local function placeBook(section: Instance, index: number): (nil) bookController.Replica:FireServer("Place", section, index) end local function splitTitleIndex(book: Instance): (string, number) local title, index = book.Name:match("^(.-)_(.+)$") return title, index end local function getBookSection(genre: string, bookName: string, volumes: number): Instance? if not BOOKS_SECTION[bookName] then if not BOOKS_GENRES[genre] then BOOKS_GENRES[genre] = libraryGenres[genre]:GetChildren() end for key, section in BOOKS_GENRES[genre] do if section:GetAttribute("Width") == volumes then BOOKS_SECTION[bookName] = table.remove(BOOKS_GENRES[genre], key) break end end end return BOOKS_SECTION[bookName] end local function complete() if MAIN_THREAD then task.cancel(MAIN_THREAD) getgenv().MAIN_THREAD = nil task.wait() end localPlayer.Character:PivotTo(exitDoor.Region.Part.CFrame) end local function organizeBooks() for genre, books in booksGenres do for _, data in books do local volumes = data.VolumeCount or 1 local section = getBookSection(genre, data.Title, volumes) for volume = volumes, 1, -1 do local book = libraryBooks:FindFirstChild(`{data.Title}_{volume}`) if not book or book:GetAttribute("Locked") then continue end while not book:FindFirstChild("Attachment") do localPlayer.Character:PivotTo(book.CFrame) task.wait() grabBook(book) end while book:FindFirstChild("Attachment") do localPlayer.Character:PivotTo(section:GetPivot()) task.wait() placeBook(section, volume - 1) end end end end end local function awake() exitDoor.DoorPart.DoorHighlight:GetAttributeChangedSignal("Enabled"):Once(complete) getgenv().MAIN_THREAD = task.spawn(organizeBooks) end awake()