Trying to make custom inventory in studio goes wrong

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I’m trying to make a custom grid-based inventory with my coding skills (if i wrote code in a really weird way please forgive me as I’m still pretty new to making clean code.), but the problem is that it makes the icon for the item multiple times because it’s picked up multiple times.

Though, the problem with this is that when it tries to count how much of the same item stacked in one slot, it counts each of the items and doesnt delete them individually. Please help! (also sorry if this sounds confusing, I’m not very good at explaining things)

		local dupes = 1
		
		for _,object in pairs(player.Backpack:GetChildren()) do
			if object.Name == itemTool.Name and object:IsA("Tool") and object ~= itemTool then
				dupes += 1
			end
		end
		for _,object in pairs(character:GetChildren()) do
			if object.Name == itemTool.Name and object:IsA("Tool") and object ~= itemTool then
				dupes += 1
			end
		end
		for _,object in pairs(player:FindFirstChild("inventory"):GetChildren()) do
			if object.Name == itemTool.Name and object:IsA("Tool") and object ~= itemTool then
				dupes += 1
			end
		end
		
		print(dupes)
		
		slot:FindFirstChild("Amount").Text = "x"..dupes
		slot:FindFirstChild("Amount").Visible = true
  1. What is the issue? Include screenshots / videos if possible!
    The error (it’s supposed to be three swords stacked into one slot)
    image

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Looked up multiple solutions over the course of a couple of hours, haven’t found any.

Well I fixed the issue of stacking, but I’ve been trying to fix another error that’s been annoying. If anyone wants to help I can provide images and my scripts here

ight imma help ya i guess so whats da new problem?

So, in this small section of code which I believe is causing the new problem is this piece of code.

What it should be doing is removing the extra slots, but obviously it isn’t doing that.

local everything = getOccupiedSlots()

for _,object in pairs(everything) do
	print(object)
	if object:FindFirstChild(tostring(item.itemID)) and mergedItem == false then
		mergedItem = true
		removeSlot(slot)
		changeValue(object,amount)
	end
end

The function for reference:

local function getOccupiedHotbar()
local occupied = {}

for _,slot in pairs(hotbarFrame:GetChildren()) do
	if slot:FindFirstChildWhichIsA("ImageLabel") then
		table.insert(occupied,slot)
	end
end

return occupied

end

This is what it’s doing:


Each time an item is obtained, it creates a new icon for the item. However, it can’t detect the icons that are being created when the object is merged, so instead it keeps the new icon and adds the amount to the older icon. My bad if this wasn’t descriptive enough or was just confusing, I’m not really used to DevForum.

Oh nevermind, I might’ve fixed it, I just had to check if there was a new icon then delete it in another place (I couldn’t delete it in the place I was trying to delete.) Thanks for offering help, though.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.