How Would I implement This type of a system?

Hello, I am very sorry if you had to see my previous posts, I really appreciate all of you for answering, but I have came to down to this.


Important , Please read before you do anything
So if you had to make a system where there is an inventory system like this, where would you start?
everything else here is just extra info

Read the “What I exactly wanted to make” part and see if you know how I would be able start making this system, what script should I make first, and for example would I make a remote event like I have now for all of the equipping or what seems like the best way to go about that.
the old system is there just so in the future It can be seen how I tried to make it .

Examples of the system for those who don’t like reading

This system needs a rework in my opinion, because it just seems a little bit messy and weird. It was not working the way I wanted it to, and even if I wanted to make it work it would be so messy and confusing to debug in the future.
So I need help figuring out how the system would work, not specifically code , but just how it would work for ex , should I maybe use an event for that and not for that ,

I need help with the basics of how it would work
What I exactly wanted to make :

**

  • Inventory that holds the player’s items that the player can equip or unequip

  • when the Player clicks a gui(any of the items inside inventory) it equips it, and puts it in another frame this Frame is a slot for the equipped item
    **

A Player has a inventory gui, the inventory gui will have all the items the player has in their datastore,

The datastore is a dictionary containing two (I might add more in the future , 2 for now) Arrays, To this point I have been using ‘Strings’ to store what items the Player currently owns.

On the start of the game (When Player joins) his inventory has all of the items, as gui objects (viewportframes) , this is an easy part , But I don’t know would I use my Previous method or a new method for this.

Equipped items have their own dictionary in the player’s datstore, that is basically a copy of the dictionary that is used for saving the owned items
Näyttökuva 2022-08-12 172937
(weapons is an array of strings that are the items equipped by the player)

The old system

Adding Owned Items from the Player's Datastore Into Gui

In the Current system this function runs when game is loaded for the player.

Simply what this would do is take a look at the player’s Datastore and look at the items the player has and add them as viewport frames using a cool module to the inventorygui.

local function setupInventory(Player)
	local Module3d = require(game:FindFirstChild("ReplicatedStorage"):FindFirstChild("Module3D"))
	local Profile = Datastore[Player]
	local Inventory = Profile.Data.Items
	local PlrGui = Player:FindFirstChild("PlayerGui")
	local InventoryMainGui = PlrGui:FindFirstChild("Inventory")
	local InventoryGui = InventoryMainGui:FindFirstChild("MainFrame"):FindFirstChild("Inventory")
	
	
	local Items = {}
	for _ , v in pairs(Inventory) do
		if type(v) == "table" then --/ Armors & Weapons
			for _, v2 in pairs(v) do
				if type(v2) == "string" then
					--/ This will print swords
					table.insert(Items,v2)
					
					
				elseif type(v2) == "table" then --/Chestplate & Helmet & Legging
					for _, v3 in pairs(v2) do
						--/ This will print all content in Chestplate, Helmet and Leggings tables
						
						table.insert(Items,v3)
					end
					
				end
			end
		end
	end
	for _, v4 in pairs(Items) do





		if v4 then

			






			local Item = Meshes:FindFirstChild(v4):Clone()


				local model3d = Module3d:Attach3D(InventoryGui,Item)

				model3d.Visible = true
				model3d.BackgroundTransparency = 0.3
				model3d.Name = v4
				model3d.BorderSizePixel = 0
				model3d.ItemName.Text = v4
		
	
	
		end	
	
		end	
	end		


So first of all the system doesn’t have a thing where equipped items go to the equipped slots at the start only when manually equipped

Equipping

Using a remote event sends details like (Player,Item,itemicon)

itemicon is the viewportframe that has a button inside that was clicked.

Item being the string used for example checking if it really is owned by the player.

What the function does is check if player owns the item he wants to equip, if so it checks that in which category does the item belong (weapons, or armors(leggings,helmet,chestplate)), then it checks if the category in the equipped items is empty or no, if not empty then it removes the viewportframe from the equippedslot of the category. it also sees if the specific viewport frame is equipped in a very wierd way with boolvalues, and if so it removes it from the equippedslot and if its not equipped it would add it.
The function


local Datastore = require(game.ServerScriptService["Data / Important"].Datastore) 
local event = game.ReplicatedStorage.Events.EquipItem
event.OnServerEvent:Connect(function(Player,Item,itemicon)
	
	local Profile = Datastore[Player]
	local Inventory = Profile.Data.Items
	local EquippedItems = Profile.Data.Equipped
	local PlrGui = Player:FindFirstChild("PlayerGui")
	local InventoryMainGui = PlrGui:FindFirstChild("Inventory")
	local InventoryGui = InventoryMainGui:FindFirstChild("MainFrame"):FindFirstChild("Inventory")
	local EquippedGui = InventoryMainGui:FindFirstChild("MainFrame"):FindFirstChild("Equipped")
	local itemtype
	
	local WeaponStore = require(game.ServerScriptService["Data / Important"].Storage.WeaponStore)
	local ArmorStore = require(game.ServerScriptService["Data / Important"].Storage.ArmorStore)
	local Items = {}
	
	for _ , v in pairs(Inventory) do
		if type(v) == "table" then --/ Armors & Weapons
			for _, v2 in pairs(v) do
				if type(v2) == "string" then
					--/ This will print swords
					table.insert(Items,v2)
                    

				elseif type(v2) == "table" then --/Chestplate & Helmet & Legging
					for _, v3 in pairs(v2) do
						--/ This will print all content in Chestplate, Helmet and Leggings tables

						table.insert(Items,v3)
						
					end

				end
			end
		end
	end
	local Helmets =	ArmorStore["Helmet"]
	local Chestplate =	ArmorStore["Chestplate"]
	local Leggings = ArmorStore["Leggings"]
	
	
	if WeaponStore[Item] then
		
		itemtype = "Weapons"
	elseif ArmorStore[Item] then
	
		if Helmets[Item] then itemtype = "Helmet"
		else
			if Chestplate[Item] then itemtype = "Chestplate"
			else 
				if Leggings[Item] then itemtype = "Leggings"
					
				end
			end
		end
	end
	

	
	
	local function isfilled(t)
		return #t > 0 
	end
	
	
	

	
	
	if table.find(Items,Item) then
		

		if isfilled(EquippedItems[itemtype]) == true  then
			
			
			EquippedGui:FindFirstChild(itemtype):FindFirstChild(Item).Parent = InventoryGui	
			table.clear(EquippedItems,itemtype)
		
		end	
		
		if itemicon:FindFirstChild("Equipped").Value == false then
			
				itemicon:FindFirstChild("Equipped").Value = true
				table.insert(EquippedItems[itemtype],Item)
			itemicon.Size = UDim2.new(1,0,1,0)
			itemicon.Parent = EquippedGui:FindFirstChild(itemtype)
		else
			itemicon.Parent = InventoryGui
			
			itemicon:FindFirstChild("Equipped").Value = false
			end	
		print(itemtype)
		print(EquippedItems[itemtype])
			

	end
end)```


I tried to make this post include every bit of information
I finally would like to have some system that isn’t messy and unefficient
Thanks alot for reading, I hope that if you can comment your way of starting a system like this.

Best of regards

1 Like