So basically I am making a backpack system and dropping items has been a real challenge, every time mouse button is up the script piece for mouse button being up runs for as many item frames in backpack.I saw a post talking about how you should link each mouse button click to the child added when using child added. Left me confused, thought maybe Id mention it. Would appreciate if anyone could help me understand what is going on here thanks.
Local Script piece that contains everything you should need to see:
InventoryGUI.ItemOrder.ChildAdded:Connect(function()
for _,ImageB in pairs(InventoryGUI.ItemOrder:GetDescendants()) do
print("DEF")
if ImageB:IsA("ImageButton") then
ImageB.MouseButton2Up:Connect(function()
local DVal = PlayerInventory:FindFirstChild(ImageB.Parent.Name)
if DVal.Value <= 0 then
return
end
local DTex = ImageB.Parent.ItemQuantity.Text
local IDrop = ImageB.Parent.Name
local MoveItem = nil
if IDrop == "9mm bullet" then
MoveItem = plerr.Backpack:WaitForChild("9mm BulletH")
elseif IDrop == "45 ACP" then
MoveItem = plerr.Backpack:WaitForChild("45 ACPH")
end
MoveItem.Parent = game.Workspace
print(MoveItem.Name)
MoveItem.RHolder.CFrame = HumanoidRoot.CFrame + HumanoidRoot.CFrame.LookVector * 3.5 + Vector3.new(0, 2, 0)
game.ReplicatedStorage.InventoryDropPickUp:FireServer(DVal, -1)
print("RAN")
DTex = DVal.Value
end)
end
end
end)