My inventory system is really buggy

I made a custom inventory system and its really buggy

Video of the problem:

Server Script:

	if item.Parent == plr:FindFirstChild("StoredItems") then
		if #plr:FindFirstChild("HotbarItems"):GetChildren() < 10 then		
			if #plr:FindFirstChild("HotbarItems"):GetChildren() > 0 then
				for i, v in pairs(plr:FindFirstChild("HotbarItems"):GetChildren()) do
					if v.Name == item.Name then
						if v.Quantity.Value + item.Quantity.Value <= v.MaxStackSize.Value then
							v.Quantity.Value += item.Quantity.Value
							item:Destroy()
						else
							item.Parent = plr:FindFirstChild("HotbarItems")
						end
					end
				end
			else
				item.Parent = plr:FindFirstChild("HotbarItems")
			end
		end
	end
	
	if item.Parent == plr:FindFirstChild("HotbarItems") then	
		if #plr:FindFirstChild("StoredItems"):GetChildren() < plr:FindFirstChild("InventoryStorage").Value then
			if #plr:FindFirstChild("StoredItems"):GetChildren() > 0 then
				for i, v in pairs(plr:FindFirstChild("StoredItems"):GetChildren()) do
					if v.Name == item.Name then
						if v.Quantity.Value + item.Quantity.Value <= v.MaxStackSize.Value then
							v.Quantity.Value += item.Quantity.Value
							item:Destroy()
						else
							item.Parent = plr:FindFirstChild("StoredItems")
						end
					end
				end
			else
				item.Parent = plr:FindFirstChild("StoredItems")
			end
		end
	end
end)

Local Script:


local rs = game:GetService("ReplicatedStorage")
local events = rs.Events

local function RefreshInventory()
	for i, v in pairs(script.Parent.InventoryBG.InventoryHolder:GetChildren()) do
		if v:IsA("ImageButton") then
			v:Destroy()
		end
	end
	
	for i, v in pairs(player:FindFirstChild("StoredItems"):GetChildren()) do
		local slot = script.Parent.InventoryBG.SampleSlot:Clone()
		slot.Parent = script.Parent.InventoryBG.InventoryHolder
		slot.Name = v.Name
		slot.ItemQuantity.Text = tostring(v.Quantity.Value)
		slot.Visible = true
		
		slot.MouseButton1Click:Connect(function()
			events.TransferItem:FireServer(v)
			wait()
			RefreshInventory()
		end)
	end
end

wait()

RefreshInventory()

script.Parent.Parent:WaitForChild("MainGui").ToggleInventoryButton.MouseButton1Click:Connect(function()
	RefreshInventory()
	script.Parent.Enabled = not script.Parent.Enabled
end)

player:FindFirstChild("HotbarItems").ChildAdded:Connect(function()
	RefreshInventory()
end)

player:FindFirstChild("StoredItems").ChildAdded:Connect(function()
	RefreshInventory()
end)

while wait() do
	if player:WaitForChild("StoredItems") then
		script.Parent.InventoryBG.InventoryHolder.CanvasSize = UDim2.new(0,0,0,script.Parent.InventoryBG.InventoryHolder.UIGridLayout.AbsoluteContentSize.Y + 10)
	end
end

I have a feeling this is an issue with the images appearing on the GUI, rather then the actually script itself. May I see the Image Buttons/Labels?

Its not something to do with the GUI, the item from the inventory folder is supposed to go to the HotbarItems folder whenever I click the item in the inventory GUI

also I check and its something to do with the code in the server

I figured it out, I was transferring the item to the hotbar slots then checking if it was in the hotbar slots and if it was in hotbar slots then I would switch it back to the inventory

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