Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Where do I start with creating an inventory system?

I'm quite new to programming in Roblox and have next to no idea what I'm doing. I've started learning lua 5.1 aka ROBLOX lua on the wiki page and the first and foremost thing I need for my game is a functioning inventory system, this isn't the first programming language I've started to learn so I know basically how to improve upon and write some form of complexity into a code, but I don't really know where my starting point for this would be. If someone would like to help me out there it would be much appreciated

Thank you, Laxus

2 answers

I would assume you'd have an understanding of where to start if you have a background of knowledge making complex code, assuming you're not speaking of webpage coding and such.

Anyways, the things you'll most likely want to know, for a simple inventory system, would be most GUI topics such as MouseEnter/Leave, MouseDowns/Ups (These are not all the correct names). Also a firm understanding on the basics such as local scripts, scripts, possibly scripting with FilteringEnabled (Not Needed), the use of Clone() and each visible Service you see when you start the game. Along with the GUI's, you'll want to understand ImageButton/Label, TextButton/Label, Frame, ScrollingFrame, and the rest.

Oh, you can't forget the use of DataStoreService!

I'll quickly tell you about clone and provide some possibly helpful links bellow.

Clone() is used to make a copy of another Instance. An example will be a part, and to do this you must get the part then tack on :Clone()

game.Workspace.Part:Clone()

Now you'll notice you can't tell anything happened, this is because you need to Parent the cloned Part to a Service, perhaps Workspace.

game.Workspace.Part:Clone().Parent = game.Workspace
  • Links

GUI Tutorials

Data Store Tutorial

Learn about tables; very helpful

I assume you understand Strings, Booleans, Creating Instances, Variables and those simple things, if not, I suggest you start using the wiki!

As well as alphawolvess' answer, there are also a few more things to do with actual cataloging the items themselves. These are more on the side of tips, so don't take this for a full answer.


Getting the Items

This should be pretty simple, you would just make

  • A) A table full of the names/ObjectValues of the items a player has
  • B) A folder with the items a player has

Then, to get all of the items, you would do one of the following for loops:

local itemsTable = {} -- or folder:GetChildren()

for key,v in pairs (itemsTable) do
	-- code (key is what you use to index the value in the table, v is the value itself)
end

for i = 1,#itemsTable do
	-- code (accessed by itemsTable[i])
end

Positioning Them

There are two ways to do this, you either make all of the boxes manually, or you generate it with a loop.

The manual way is obviously the easiest on the mind, but the latter is better.

For the manual one:

  • Try and name the boxes consistently, for example: "Box1",``"Box2","Box3". This will allow them to be easily accessed by script.

For the generated one:

  • Use something like an offset variable which allows you to consistently space boxes. For example: box1.Position = prevPosition + offset

  • It would be easier to generate the boxes and their items in the same loop. This may of course be a bit more challenging for debugging and stuff.


Hopefully this was useful to you :)

~TDP

This discussion is preserved as it was. New answers, comments, and votes are closed.