Ad
Log in to vote
0

Having trouble with Inventory, will a decent scripter please help me?

Asked by 11 months ago
Edited by Goulstem 11 months ago

So, here's the layout of my inventory as simple as possible so that you understand:

  • InvGui ("ScreenGui")
    • localscript (for getting certain resources in the game)
    • Inventory ("Frame")
      • slot1 ("Frame")
        • SlotValue ("StrongValue") (value = "zero")
        • Amnt ("NumberValue") (value = 0)
        • SlotImageButton ("ImageButton")
          • localscript ( for the button functions )
        • buttonframe ("frame")
          • drop ("TextButton")
          • cancel ("TextButton")

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?

Edited ~ Format and tab your code correctly!! Use the Preview button if you're unsure.
0
whenever I get the wood in my inventory again is drops it by an extra -1 every single time.. why is this, did I do something wrong? darkhenry 2 — 11mo
1
Please paste the code like this, so it is readable: http://prntscr.com/hk566e Andorks 23 — 11mo

1 answer

Log in to vote
0
Answered by 11 months ago
Edited 11 months ago

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
Ad

Answer this question