Roblox Visual Inventory with Safe Drag-and-Drop
Generate a professional visual inventory system for Roblox, with a slot-based interface, drag and drop items, stacking, position swapping, stack limits, and visual feedback during movement. The prompt guides the AI to adapt the solution to the real structure of your project before producing the code.
The solution prioritizes a secure client-server architecture: the interface runs locally, but every real inventory change is validated and confirmed by the server. Ideal for RPG, survival, tycoon, simulator, adventure games, and any experience that requires reliable item management.
Act as a senior Roblox developer, specialized in Luau, client-server architecture, responsive interfaces, and anti-exploit security. Create a complete visual inventory system with drag and drop, ready to integrate into my Roblox Studio project. Before writing the code, analyze and use the context below. If any field is empty or does not exist in the project, adopt consistent names and make the assumptions explicit at the beginning of the response, without interrupting the solution with unnecessary questions. MY GAME CONTEXT (I will fill this in before sending): - Current structure in the Explorer (ScreenGui, Frames, templates, folders, and scripts): [PASTE HERE] - Name and location of existing RemoteEvents/RemoteFunctions: [PASTE HERE] - Data source for items/inventory (DataStore, ProfileService, Attributes, ModuleScript, leaderstats, etc.): [PASTE HERE] - List of available items and properties (Id, name, icon, quantity, MaxStack, rarity, weight, etc.): [PASTE HERE] - Number of slots and special rules (hotbar, expandable inventory, maximum weight, non-stackable items, etc.): [PASTE HERE] - Desired visual behavior, target resolution/platform, and UI style: [PASTE HERE] - Existing persistence system and internal APIs that must be preserved: [PASTE HERE] FUNCTIONAL OBJECTIVE: Implement a grid inventory with visual slots, icon, quantity counter, and empty state. The player must be able to click/tap and drag an item to another slot. The system must support: moving an item to an empty slot, swapping two items, stacking compatible items up to MaxStack, keeping the overflow in the source slot, preventing invalid actions, and updating the interface immediately after server confirmation. Include visual feedback during dragging: a floating item following the cursor or touch, valid/invalid highlight on the target slot, and visual restoration if the operation is rejected. The system must work with mouse and touch; gamepad support is desirable if it does not significantly increase complexity. REQUIRED ARCHITECTURE: 1. Generate all necessary files, not just an isolated snippet. For this system, deliver at minimum: - A ModuleScript with item definitions/utilities in ReplicatedStorage.Shared (or adapt to my context). - A RemoteEvent in ReplicatedStorage.Remotes for move requests and a RemoteEvent for inventory synchronization/update, if my remotes are not compatible. - A server Script in ServerScriptService, responsible for maintaining or accessing the authoritative inventory state, validating and applying each operation. - A LocalScript in StarterPlayer > StarterPlayerScripts or inside the ScreenGui in StarterGui, responsible exclusively for UI, input, and rendering. - If necessary, a Slot template in ReplicatedStorage or inside the ScreenGui, detailing its expected hierarchy. 2. Declare for each file: suggested name, exact type (Script, LocalScript, or ModuleScript), exact location in the Explorer, and dependencies. 3. Do not invent obscure APIs or use syntax incompatible with current Luau. Use WaitForChild judiciously, disconnectable connections when applicable, task.spawn/task.delay when appropriate, and Luau typing where it makes the code safer and more readable. SECURITY AND VALIDATION: The server is fully authoritative. The client can never decide quantity, final item, damage, currency, or the real inventory state. When receiving the drag request, the server must validate Player, source/target indices, data types, slot existence, source item, stacking compatibility, MaxStack, and all blocking rules. The client should send only slot indices and an operation intent, never complete inventory tables or trusted quantities. Implement a simple per-player rate limit, handling for stale state, and safe rejection of malformed payloads. Never trust values sent by the client. CODE QUALITY REQUIREMENTS: Provide complete, executable, and commented Luau code, with no pseudocode, no omitted functions, and no use of "..." as a stand-in for implementation. All code must be placed in separate markdown blocks using ```lua. Preserve the separation between data, domain rules, network, and presentation. Avoid recreating the entire UI unnecessarily; use deterministic rendering of changed slots or a simple, reliable full refresh, briefly justifying the choice. Handle player disconnects and cleanup of connections/state on the server. RESPONSE FORMAT: 1. List the assumptions made and the final Explorer tree. 2. Briefly explain the client-server flow of the drag-and-drop operation. 3. Deliver each file with a title containing its path and type, followed by its complete ```lua block. 4. Provide any required manual UI setup, including exact names of Frames, ImageLabels, TextLabels, UIGridLayout, attributes, and templates. 5. End with an objective test plan in Roblox Studio: local test with 2 players, scenarios for moving, swapping, stacking, exceeding MaxStack, dropping outside a slot, invalid remote payloads, and reconnection. Also include how to find errors in the Output. If the context I provided already includes structures or remotes, adapt to them and do not duplicate systems. If there is incompatibility, explain the minimal required change and deliver a safe version ready to paste.