InventoryUtils
Stateless helper functions for inventory operations
| Function | Returns | Description |
|---|---|---|
| GenerateUUID() | string | Generates unique identifier for item instances using HttpService |
| CanStack(item1, item2, checkRarity) | boolean | Checks if two items can stack based on ID and metadata equality |
| FindEmptySlot(slots, maxSlots) | number? | Returns first empty slot index (1-based) or nil if full |
| ParseToolMetadata(tool) NEW | table? | Extracts all Attributes from a Tool for persistence |
CanStack Deep Dive
How stacking eligibility is determined
Stack Check Logic
Pseudocode
1. Check ID match: item1.Id == item2.Id 2. Strict Check: Name, Rarity, and Type MUST match exactly 3. Blacklist: Check Settings.RarityBlacklist (e.g. Legendary) - If blacklisted, return false 4. Return true if all checks pass
ItemSpawner
Physical tool instantiation and world interaction
| Function | Returns | Description |
|---|---|---|
| SpawnTool(player, itemId, metadata?) | Tool? | Clones tool from ServerStorage, applies metadata as Attributes Character Check |
| DespawnTool(player, tool) | void | Destroys a tool if it belongs to the player's character |
| DropTool(player, itemId, amount, metadata?) | void | Creates a pickup in the world at DropDistance from player |
SpawnTool Flow
How tools are instantiated on equip
Spawn Flow
Pseudocode
1. Check player.Character exists (safety) 2. Find tool template in ServerStorage.Tools[itemId] 3. Clone template 4. Apply metadata as Attributes via SetAttribute() 5. Parent clone to player.Character 6. Return tool instance
⚠️ Safety Note:
SpawnTool includes a character existence check to prevent errors when players die during
equip.