As a Roblox developer, it is currently too hard to manipulate and control inventories on NPCs.
I can make a folder inside server storage or somewhere but it wont be organized and I would have to mess up my code by a lot, as well if I have 30 npcs in game then I would have to get 30 folders in server storage which will be visually confusing if other objects are in there.
A functional inventory/backpack that is inside a humanoid will adress the issue.
If Roblox is able to address this issue, It will help me as a developer in the next cases.
A game where a player or another NPC steals a tool from an NPC backpack without killing them, or to give an NPC a tool from your backpack
A game where you can swap random items with npcs
A new weapon that is being added to the NPC while the NPC is holding another weapon, without the new weapon to interfere/replace the current weapon the NPC is holding.
Is a backpack not just another container for tools/instances? I don’t see how it’d be any more organized than the ServerStorage psuedo-backpack approach. It’d be functionally identical to how players can equip tools anyway.
lets say you want to steal a “door key” from a target npc. with players having backpacks there is no problem, the issue is npcs dont have backpacks, how would you call a server storage folder from a player script. lets say you have more than one npc how would you know which is which?
These are two simple implementations that accomplish the same thing.
Drop key on death:
local char = script.Parent;
local hum = char.Humanoid;
function dropKey()
local key = game.ServerStorage.Items["Door Key"]:Clone();
key:PivotTo(char:GetPivot());
key.Parent = workspace;
end
hum.Died:Connect(dropKey);
Give key when ProximityPrompt is triggered:
local char = script.Parent;
local hrp = char.HumanoidRootPart;
local prompt = hrp.StealPrompt;
local hasGivenKey = false;
function onPromptTriggered(plr)
if (hasGivenKey) then
return;
end
local key = game.ServerStorage.Items["Door Key"]:Clone();
key.Parent = plr.Backpack;
hasGivenKey = true;
end
prompt.Triggered:Connect(onPromptTriggered);
I’ve designed plenty of NPCs who utilize tools, and their programming handles what tool is currently in use. From a design standpoint, the backpack only exists as an interface because players interact with the game differently than an NPC would.
Your use case is rather specific. As @ellienonekomimi said, a backpack is essentially a protected folder whose functionality is defined by core scripts. It is a member of player instance in the dedicated service (Players).
The question is whether to move logic that can be handled by game scripts to engine and core scripts, and I’m afraid that would cause more bloat than benefit.
Creating a backpack in the NPC model itself involves placing a folder in it upon its creation at most. The rest is moving the tools between these folders and the players’ backpacks.
Of course, it’s usually nice to have a more centralised place to store NPC info, which requires some sort of distinction between them, like unique IDs. Each player also has a unique id by which they are searched.
Hence it’s about considering whether to have the engine do that for you and providing all the necessary interface, or creating this yourself. It feels like creating a custom inventory service to suit your needs, especially in OOP or ECS styled systems, is a lot more practical.
I fail to see how it is any less disorganized than how the player object stores its backpack.
It would be very simple and straightforward to make your own NPC backpack system by making a folder when your NPC spawns, parenting the folder in ServerStorage, and keeping track of it with an ObjectValue should you want the backpack accessible to other systems in your game.
It will be better if the engine provided me an ability for NPCs to store tools in a backpack instead of creating a folder with a script for each npc and then use require to call the folder for each of them
If you want to access these functions using regular folders, you could just recreate them taking the humanoid or character as an argument and detecting the backpack folder.
After that, you could probably make the EquipTool function by just taking the tool as an argument to be parented under the character
The issue is that the engine can’t just change to accommodate for things that can be made with basic applications of scripting, it would end up making lots of things deprecated and would break existing games working around the old systems.
It’s highly unlikely they will consider your request, because engine changes are used primarily to fix bugs or provide access to things that scripting normally can’t allow.
This is not a change of the existing humanoid or player backpack, its more of adding a new “inventory” class so we can be able to store tools there for easier development.