Custom inventory backpack

Hello. This is my first post on the forum so my apologies in advance if this is the wrong place to post this.

I am trying to make a simulator style backpack with a custom inventory capacity but I am not too sure where to start. I have looked around the forum and youtube but none of the videos have really helped me reach this goal. If you guys have any suggestions on what I should do they’d be greatly appreciated.

Thanks!

1 Like

Custom inventory can be a little daunting at first, but once you get the bases down it’s not too hard. Are you storing tools that can be equipped? If so, Roblox has API so that you can manually equip tools through scripts using Humanoid:EquipTool(tool ref). This will be called when you want to equip the tool through your system by firing a RemoteEvent on the server somewhere.

Since tools are kept in the player’s Backpack under the PlayerModel, you don’t need to worry about storing them in a new way. The main thing to think about is the interface (GUI). When you open the inventory, loop through the player’s backpack and display the items in rows or however you please using for i,v in pairs and so on.

I recommend planning out how your GUI will look at first, how you do this only matters to you so you can draw it or whatever to get a clearer idea of where to start.

Hello to the developer Forum,
you need to change the place of this post and put it in the scripting support category that is its right place

1 Like

Hey! I have provided a screenshot I took earlier so you have a better idea of what I am trying to do.
Currently I have the GUI set up and the little colourful parts are candies, the rest is self explanatory.
I have coded it so that when you click the candy, the candy is removed from the baseplate and it is added to your inventory via NumberValues. I also have a test part that works as a shop which removes those candies and gives you coins instead, the same way the candies work.

Basically I want the inventory to work in a way so that the max capacity cannot be surpassed, there are no tools being equipped. I also have a total of 5 backpacks that I’d like for them to range in capacity while being interchangeable although for right now I’m trying to get the max capacity working first.

Okay so for custom things, to store them you should make a folder containing your items that are int/number values. Somewhere else in the player you could also store what kind of backpack the player has. You can either use an IntValue to store the backpack ID, or a string value for the name of the backpack.

To limit the amount of things a player can have, in your collection script that adds to how much of a thing the player has, you could check in there for what kind of backpack the player has and then allow/disallow the addition.

Pseudocode for collection:
function GetRedCandy(amount)
    local max_Storage = 5 -- default limit
    if PlayerBackpackType == "Big" then
        max_Storage = 12
    elseif PlayerBackpackType == "Super" then
        max_Storage = 25
    end
    
    if RedCandy+amount > max_Storage then
        print("Not enough space!")
    else
        RedCandy += amount
    end
end

The code above is as basic as it can be, but should work in theory!

1 Like

Use either an IntValue or a variable with a set Int. You can then subtract this each time the player adds onto the inventory, and then add to it when a player removes something from their inventory.

Think of it as like ammo for a gun