So, here's the layout of my inventory as simple as possible so that you understand:
now, this is where I'm having trouble, in my local script located inside of the SlotImageLabel, I have this script:
local plr = game.Players.LocalPlayer local slot1 = plr.PlayerGui:WaitForChild("invGui"):WaitForChild("Inventory"):WaitForChild("slot1") slot1.SlotImageButton.MouseButton1Click:Connect(function() if slot1.SlotValue.Value == "Wood" then slot1.buttonframe.Visible = true slot1.buttonframe.drop.MouseButton1Click:Connect(function() slot1.Amnt.Value = slot1.Amnt.Value - 1 slot1.SlotLabel.Text = slot1.Amnt.Value if slot1.Amnt.Value <= 0 then slot1.Amnt.Value = 0 slot1.buttonframe.Visible = false slot1.SlotValue.Value = "zero" slot1.SlotLabel.Text = "" slot1.SlotImageButton.Image = "" end end) end end)
It works the first time, it drops the wood by -1 the problem is that whenever I re-get the wood (by walking over a brick) and I click drop, it drops the Amnt.Value by -2 the second time, then it drops by -3 the third time, then by -4 the fourth time.. why is it like this, can anyone help me to fix this?
For loops would be ideal in this situation.
Inventory Slot1 Ammt Item Slot2 Slot3
for i,v in next, Inventory:GetChildren() do v.Drop.MouseButton1Click:Connect(function() if v.Item.Value == “Wood” then v.Ammt.Value = v.Ammt.Value-1 > 0 and v.Ammt.Value-1 or 0 end end) —other events end