Cloning multiple items?
So I wrote my script as an inventory pick up script. When I pick up ammo it adds the correct amount to the ammo value but when I pick up an object, it clones multiple items into my inventory.
02 | torso = char:findFirstChild( "Torso" ) |
03 | player = game.Players.LocalPlayer |
04 | control = player.Control |
05 | text = player.PlayerGui.Cam.BlackOut.Interact |
06 | resources = game.Lighting.Resources |
07 | mouse = player:GetMouse() |
08 | stats = player:findFirstChild( "Player Stats" ) |
09 | inventory = stats.Inventory |
12 | select = player.PlayerGui.Cam.LookAt |
14 | function Distance(target) |
15 | local p = target.CFrame.p |
16 | local t = torso.CFrame.p |
17 | local distance = (p-t).magnitude |
18 | if distance < = maxdistance then |
30 | function Grab(item,id,key) |
32 | local class = id.Value |
33 | if class = = "Ammo" then |
34 | local value = inventory.Ammo:findFirstChild(item.Name) |
35 | value.Value = value.Value + item.Amount.Value |
37 | grabbable:disconnect() |
39 | if class = = "Pistol" then |
40 | local pistol = resources.Weapons.Pistol:findFirstChild(item.Name):clone() |
41 | pistol.Parent = inventory.Weapons |
43 | grabbable:disconnect() |
49 | if control.Value = = true then |
50 | local target = mouse.Target |
52 | local id = target.Parent.Parent:FindFirstChild( "Id" ) |
54 | local item = id.Parent |
55 | local grab = Distance(target) |
60 | grabable = mouse.KeyDown:connect( function (key) Grab(item,id,key) end ) |
73 | mouse.Move:connect(Look) |