Open Sourced Inventory/Backpack system

Seeing that there are not very many good open sourced inventory/backpack systems, I decided to write one.

The current default Roblox backpack has a max of 10 slots.
image
What if you wanted to change the quantity or aesthetic of these slots?
A custom inventory requires a lot of boilerplate code. If it’s your first time writing an inventory system, you’re bound to run into some annoying bugs as well.

That’s where this module comes in!
Here’s how it works:

Setup

  1. Create a folder to keep all the slots
    image
  2. Inside the folder, create an ObjectValue for every slot you want and name this Slot ObjectValue with the desired activation Enum.KeyCode name. You can find a list of all the Enum.KeyCode names here
    image
    These ObjectValues will get auto-assigned tools as their values when the user picks up tools.
    Whenever the user presses a key, if there is an ObjectValue with the same name under this folder, that ObjectValue’s tool will be equipped.
    Note: The order in which these are inserted matters. The first inserted value will be the value that gets a tool assigned first, the second inserted will get assigned second, etc.

  1. Use the module’s function on the folder
    image
    This will return an Equipped ObjectValue.
    The Equipped ObjectValue will always be set to the currently equipped Slot ObjectValue.
    For clarification, doing EquippedVal.Value.Value would return a tool the player would be holding.

Once these elements are set up, you are free to do the graphical side however you’d like!
(There’s a GUI that comes with the module which you can use as a base template)

You can also program things to adjust the slot position of tools.
The following, for example, is a function that would switch the items in two slots:

function switchSlots(slot1,slot2)
	local slot1tool = slot1.Value
	slot1.Value = slot2.Value
	slot2.Value = slot1tool
	return true
end

I tried to make this post as simple and detailed as possible, however, don’t worry if this post doesn’t make sense to you at first glance.
The asset comes with an example backpack GUI that you can play around with and use however you’d like.

Planned updates:

  • Infinite backpack size
  • Example draggable inventory
  • Item stacking? (maybe…)
116 Likes

I have never thought of increasing the default amount of slots.
Very Interesting !

2 Likes

I like your inventory system you made! I don’t know if you can but you can make like a system that if the player have 2 tools of the same type (like 2 swords) in the slot will show one sword and at the top there will be a text saying x2, meaning that you have 2 swords.

8 Likes

This inventory system might be really helpful in a really big number of games, but i was wondering if this allows you to change the UI of the tools slots ? If so, that would be really amazing.

1 Like

Is this XBox and Touch Device compatible?

3 Likes

This is nice and helpful. Many players could make use of this

1 Like

I’ve had that warning before. I don’t remember the exact details, but I do remember that putting in a wait() before trying to change the parent made the warning go away. Something to do with trying to change the parent on the same frame that roblox code is trying to set it I think.

1 Like

It’s not that hard to edit it to be XBox or Touch Device compatible, but by default no.

In regards to your Side Notes section involving the reparent warning – This is easily resolvable.

In case you are unaware – This “unexpected parent change” warning is thrown to prevent event spamming to flood the event queue.

One example of code that this warning protects against is:

local p0 = workspace.Object0
local p1 = workspace.Object1
p0.DescendantAdded:Connect(function (d)
    d.Parent = p1
end)
p1.DescendantAdded:Connect(function (d)
    d.Parent = p0
end)

Parent something to p0 or p1 and you suddenly have something spamming the ever living crap out of Roblox’s backend event system with DescendantAdded event calls.

When this warning displays, Roblox automatically yields until the next event pipeline flush (effectively identical to calling wait()).

If I read your code correctly, you can resolve this issue by going to line 101, adding a newline into that condition, and before calling removeToolFromSlots(tool), add wait(). The code here runs on AncestryChanged (when the parent is changed) and removeToolFromSlots() instantly changes its parent again.

5 Likes

Where does the ModuleScript go?

Anywhere the LocalScript can access it.
In the example GUI provided, I simply parented it to the LocalScript itself.

1 Like

Should I make a version of this that doesn’t use ObjectValues?

  • Make a version of this that doesn’t use ObjectValues
  • No, using ObjectValues is nice because there’s no need to memorise custom syntax

0 voters

It would basically be the same thing but with tables instead of a folder

1 Like

I’ve fixed the unexpected parent change bug and another minor bug.
It was happening because the custom Backpack and the default Roblox Backpack were conflicting.
If anyone finds any bugs please DM me.

With the slot values supposedly in order, wouldn’t they just go from Eight to Zero straight down? Aswell as the “Equal” NumberValue, what is that for?

Thanks for releasing this :slight_smile:

No


You might be confused because Roblox Studio’s explorer arranges the values alphabetically, but it’s the order in which u insert the objects that matters. I’ll admit this isn’t the best way to do ordering, but it’s pretty simple/intuitive. I don’t see it breaking any time soon. It’s mainly for knowing which slot to auto-assign tools to. When a tool is given to the player, it goes to the first available slot in this order.


The names correspond to whatever Enum.Keycode you want for activation (I said this in Setup step 2).
By naming it “Equals”, you bind that slot to Enum.Keycode.Equals
It is shown as slot 12 on the GUI.

For example, if you were to rename it to “Tab”, then the activation key would become the Tab key.

1 Like

In you next inventory system could you teach us how to implement touch and controller support - I am familiar with enum.Keycode but I have no clue on how to scroll through the inventory using LB and RB

4 Likes

How do I edit this to a state where when a new tool is added, the oldest tool is removed?

The same way you would do that with the default inventory.
Something like this

Player = game.Players.LocalPlayer
Backpack = Player.Backpack

oldestTool = Backpack:GetChildren()[1]

Backpack.ChildAdded:Connect(function(addedTool)
    oldestTool:Destroy()
    oldestTool = addedTool
end)
2 Likes

Hi there~ @dispeller

Thank you for sharing your creation with us, this is very interesting stuff.

Would you kindly create a link to Source code (preferably Github and/or Pastebin) for people who want to read the source but don’t have any access to a PC or maybe want to contribute to the source

no

jk lol
sure thing
https://pastebin.com/raw/EPzEeLQf

3 Likes