Inventory Scripting tutorials?

Anyone Know any good inventory scripting tutorials for an inventory like this?

6 Likes

Depends on what exactly you are trying to store, if you are trying to store tools then I would do an adaptation similar to this, except of course modifying it to your needs:

If you are storing armor and such, and character customization, then I would go for something like this:

8 Likes

What if I am trying to store both armor and tools?

1 Like

Then you can learn how to do both, and combine them based on your needs.

1 Like

Depending on what you want odds are you won’t find everything in one tutorial, for stuff like this I look at multiple examples/tutorials and learn what I need

Turns out for more advanced inventories with stacks and slots you likely won’t find much or anything based on roblox, so when this happens I actually research non roblox/non lua examples and it helps a lot

reading languages you aren’t familiar with can be tricky but most of the time you can get the general idea of it because they tend to have comments and such

What I do is have a item module with all items/armors etc with IDs so instead of actually storing all the data of an item in a players inventory you only need to store the ID

Info.Items = {
	{ID = 1,
	Name = "Basic Pickaxe",
	Type = "Tool",
	ToolType = "Pickaxe",
	Resources = {["Wood"] = 5, ["Stone"] = 3},
	Eff = 5
	},
	
	{ID = 2,
	Name = "Basic Axe",
	Type = "Tool",
	ToolType = "Axe",
	Resources = {["Wood"] = 5, ["Stone"] = 2},
	Eff = 5
	},	
	
	{ID = 3,
	Name  = "Basic Pickaxe",
	Type = "Tool",
	ToolType = "Pickaxe",
	Resources = {["Wood"] = 5, ["Stone"] = 2},
	Eff = 5
	},
	
	{ID = 4,
	Name  = "Wood",
	Type = "Resource",
	StackSize = 77
	},
	
	{ID = 5,
	Name  = "Stone",
	Type = "Resource",
	StackSize = 77
	},
	
	{ID = 6,
	Name  = "Iron Helm",
	Type = "Armor",
	ArmorSet = "Iron Armor",
	ArmorType = "Head",
	Defense = 10
	},	
	
	{ID = 7,
	Name  = "Iron ChestPlate",
	Type = "Armor",
	ArmorSet = "Iron Armor",
	ArmorType = "Chest",
	Defense = 25
	},
	
	{ID = 8,
	Name  = "Iron Leggings",
	Type = "Armor",
	ArmorSet = "Iron Armor",
	ArmorType = "Legs",
	Defense = 20
	},
	
	{ID = 9,
	Name  = "Basic Cabin",
	Type = "Structure",
	StackSize = 77,
	Resources = {["Wood"] = 35},
	Defense = 250
	},
	
	{ID = 10,
	Name  = "Basic Wall",
	Type = "Structure",
	StackSize = 77,
	Resources = {["Wood"] = 15},
	Defense = 550
	},	
			
}

Player’s inventory could be something like

{
{ID = 2, Quantity = 5}
{ID = 4, Quantity = 1}
}

and whenever you need the items info you just search the item module with the item ID

Also if you’re familiar with metatables, or willing to learn you can set the metatable of items in the player’s inventory to the matching item in the item module

so you can type playerInventory[1].Name and get the name of the item without actually having all of the info stored in their inventory etc

3 Likes

Does anyone know a video or a tutorial online somewhere for an inventory script similar to Dungeon quest? or Adopt me?


image

1 Like

I’m not sure if this is the best way because I’m not good at coding, but here’s my attempt:

Make a scrolling frame and use a UIGridLayout : UIGridLayout

Everytime a person buys something, it adds an ImageButton containing a Value (for the id/name etc.) and a script that makes it that when you click it, it adds the tool in the players backpack.

2 Likes

I’m still learning inventories, but I’ll help you out with what I know

Server

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SerialModule = require(script.Serial)
-- a module that I wrote that allows us to get a unique serial to use for item identification 
local SendInventoryRE = ReplicatedStorage.SendInventory
-- remote event for sending data

local PlayerInventories = {}

local Items = { -- list of all game items (the index is the ID)
	[1] = {
		Name = "Wooden Sword",
		Type = "Weapon",
		Damage = 5
	},
	[2] = {
		Name = "Iron Sword",
		Type = "Weapon",
		Damage = 25
	}
}



function CreateItem(ID) -- returns a copy of an Item with the given ID
	
	local item = Items[ID]
	if item then
		
		local newItem = {}
		
		for i, v in pairs(item) do
			newItem[i] = v
		end
		
		return newItem
		
	end
	
end

function AddItem(Player, ID) -- adds a item to the player's inventory
	local playerInventory = PlayerInventories[Player]
	if playerInventory then
		local uniqueSerial = SerialModule:GetUniqueSerial(playerInventory)
		playerInventory[uniqueSerial] = CreateItem(ID)
		-- now we have added a new item with a random serial
	end	
end

function PlayerAdded(Player)
	
	PlayerInventories[Player] = {}
	-- sets up a player's inventory
	
	for i = 1, 10 do
		AddItem(Player, math.random(2))
	end
	-- adds 10 random items to inventory
	SendInventoryRE:FireClient(Player, PlayerInventories[Player])
	 -- sends client their inventory
end


function PlayerRemoving(Player)
	PlayerInventories[Player] = nil
end

Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerRemoving)

Client

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SendInventoryRE = ReplicatedStorage:WaitForChild("SendInventory")

SendInventoryRE.OnClientEvent:Connect(function(Inventory) -- we recieved the inventory
	for serial, infoTable in pairs(Inventory) do
		print(serial .. " " .. tostring(infoTable))
	end
end)

Output
image

also the reason a random serial is generated for they key is because it makes client to server actions possible, like

EquipEvent:FireServer(Serial)

and the server will equip the item with the sent Serial, if it exists

my code is just an example to give you an idea on how to create an inventory system

feel free to ask any questions, or to correct me if I did something wrong

Place File
InventoryExample.rbxl (17.2 KB)

3 Likes

Why use recursion twice in the function?

If you want to create an inventory like this you’ll need to find someone who is pretty good at scripting because it’s not a really beginners scripting included in here. If you’d like to create an inventory on your own then you should think logicaly on what every box should do and then script it. Also there is a lot of tutorials on YouTube and other social media but if you don’t really know what you are doing then it’s useless. I hope this reply helps and no offense.

3 Likes