How do I make an Equipping system

Hello , I have been trying to make an system or an event that equips or unequips an item.
I have a big problem at

if #EquippedItems[itemtype] ~= 0 then

‘itemtype’ is the type of a item it should look for and ‘equipped items’ is this:

Näyttökuva 2022-08-11 183814

I am trying to find from the ‘Equipped dict’ the itemtype which is either one of those tables inside the ‘Equipped’, so rn itemtype can for ex be “weapons” so I want to look if the weapons table has weapons.

Note, to make this easier for anyone helping I can make it so the armors are not in those specific tables inside the armor dictionary and just identify their armor type another way, so if you can find a solution for only 2 tables / dictionarys that should also work so being specific with the chestplate,helmet,leggings tables is not required for me to make it work

Also, if I clear the table it makes the table completely nil , so also I would like to only clear the contents of the table,

if table.find(Items,Item) then --checks if player has the item unlocked
		

		if #EquippedItems[itemtype] ~= 0 then --here is the PROBLEM OF THE SCRIPT,

			
			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

Thanks if you actually took your time, usually these "bit longer posts " are not read by people

Also , can someone help me with getting replies to my problem, I see others get solutions or answers a lot faster

I couldn’t understand the rest of your question, but I could understand the “big problem”:

An unfortunate thing is that the length of a mixed table is only taken for the array-like part.

What I’m saying is that, for example, the length of this table:

{
[1] = "one",
["hello"] = "hi",
[2] = "two"
}

is not 3, it’s 2.

Here is a function I just made to check if a table has anything in it:

local function isfilled(t)
	for _ in pairs(t) do return true end
	return false
end
--returns false if the table is empty, true otherwise
1 Like

Thank you for the reply, The other thig was that

was saying it was nil for some reason, I don’t know if it is still a problem.
So that was kind of my main problem, I will take a look does your solution work for me in a bit

I’m not sure if you’re quoting the correct part, table.insert doesn’t print or return anything.

I can’t see the definition of the variable Item. Are you sure it’s non-nil?

is giving me an error (table expected got nil) invalid argument #1 to ‘pairs’
weird the table is there tho
Näyttökuva 2022-08-12 172937