Inventories and backpacks for NPCs' Humanoids

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.

  1. 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
  2. A game where you can swap random items with npcs
  3. 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.
2 Likes

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.

4 Likes

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?

2 Likes

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.

4 Likes

That will be a mess with multiple weapons/tools/items. as well as with multiple players or NPCs. backpacks will help me orginanize the flow

Humanoid:EquipTool(Humanoid.Inventory.Rifle)

or

Humanoid.Inventory:AddTool(workspace.tool)
2 Likes

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.

5 Likes

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.

4 Likes

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

2 Likes

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

3 Likes

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.

3 Likes

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.

2 Likes

You should consider making your own class because it’s unlikely the developers will make a new inventory class for the reasons I stated previously

1 Like

I dont think its possible to create classes in roblox

1 Like

They are likely referring to Luau OOP with ModuleScripts.

1 Like

Okay i see you guys are not interested in adding an inventory class to roblox so i will drop this topic

1 Like

yeah, i dont even know how a inventory would be made

1 Like

It should be a folder where the tools are inside it but they are not shown in the workspace

1 Like

Yeah, you could just make a custom system parenting tools to ReplicatedFirst instead?

1 Like

you said ‘Intentories’ in the title as a typo :skull:

1 Like

Thank you for noticing. Its fixed.

1 Like