My Inventory System adds multiple items and not just one, why is that?
Basically, I have got the Inventory System to work pretty darn well. When the player presses E on their keyboard the item is then removed from the world and put into their inventory.
The problem is that when the item is picked up, multiple quantitys of that time is added and not just one. It should add 1 item and not like 6.
01 | local player = game:GetService( "Players" ).LocalPlayer |
02 | local char = player.Character |
03 | local mouse = player:GetMouse() |
04 | local inv_gui = script.Parent.Inventory |
05 | local inv = player:WaitForChild( "Inventory" ) |
08 | for _,item in pairs (workspace [ "WinterSurvival" ] .DroppedItems:GetChildren()) do |
09 | if (item:IsA( "Model" )) then |
12 | for _,kid in ipairs (par:GetChildren()) do |
13 | if (kid:IsA( "Model" )) then |
14 | itemID = kid.ItemID.Value |
20 | findID(game:GetService( "ReplicatedStorage" ).Items) |
21 | local label = script.Parent.PressE |
22 | if (char:FindFirstChild( "Torso" ).Position - item.Handle.Position).magnitude < 7 then |
23 | label.Text = "Press [e] to pick up '" ..item.Name.. "'" |
26 | mouse.KeyDown:connect( function (key) |
27 | if (key:lower() = = "e" and debounce) then |
29 | for _,slot in pairs (inv:GetChildren()) do |
30 | if (slot.ItemID.Value = = itemID) then |
31 | slot.Qty.Value = slot.Qty.Value + 1 |
36 | if (slot.ItemID.Value = = 0 ) then |
38 | inv_gui [ slot.Name ] .Qty.Visible = true |
39 | slot.ItemID.Value = itemID |
40 | slot.Value = item.Img.Value |