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

Im trying to make a inventory system, how should i go about it?

Hello there, I'm trying to make a custom inventory system. I've been searching for tutorials but most of them are way too long or just some free model. if you have good tutorials or you have made an inventory system your self how did you go about it? I'm trying to get a good direction to start with.

1 comment

0

Hi i made my inventory system i can send you scripts And explain what i made if you want write on my discord Jenda_1#4077

1 answer

You could use a table. Here's how I would do it:

local inventory = {}

If you are making custom objects that your inventory can contain, I would suggest learning Lua Object Orientated Programming (OOP) and metatables. I'm not going to go in depth in this code, but here's how I would simulate an object (in a modulescript):

local object = {}
object.__index = object

function object.new(name, durability, maxdurability)
	if not maxdurability then maxdurability = 100 end

	local objProps = {} -- A table used for storing the object's properties (i.e. variables and functions
	setmetatable(objProps, object)

	objProps.Name = name
	objProps.Durability = durability
	objProps.MaxDurability = maxdurability

	return objProps
end

function object:IncreaseDurability(increment)
	self.Durability += math.clamp(self.Durability + increment, 0, self.MaxDurability)
end

We can add objects to the table like this:

local Object = require(game.ServerScriptService.Module) -- require(location of modulescript)

local Pickaxe = Object.new("Pickaxe", 56, 250)

table.insert(inventory, Pickaxe)

print(Pickaxe.Name .. " has been obtained.")

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