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.
COMMUNITY QUESTION
Im trying to make a inventory system, how should i go about it?
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.

1 comment
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