Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Dropping the Precise item Clicked?

Asked by 6 years ago

Hello!

I am having trouble getting the item I want to drop.

I can get an item to drop, specifically, it drops the first item on the list, Bandage or Ammo but I want to be more precise with dropping the item you specifically clicked.

Any help please?

OptionMenu.Drop.MouseButton1Down:Connect(function()
    --local ObjItem = Bin.Background.Backpack:FindFirstChildWhichIsA("GuiButton")
    for i,v in pairs(Player.Backpack:GetChildren()) do 
        if v:IsA("Tool") then
            if v:FindFirstChild("Type") ~= nil and v.Type.Value == "Medical" then
                DropItemEvent:FireServer(v)
                Dropped:Play()
                OptionMenu.Visible = false
                break
            elseif v:FindFirstChild("Type") ~= nil and v.Type.Value == "Ammo" then
                DropItemEvent:FireServer(v)
                Dropped:Play()
                OptionMenu.Visible = false  
                break
            end
        end
    end
end)
0
what? ILikeTofuuJoe 1 — 6y
0
Try replacing both of the "FindFirstChild" on line 5 and 10 with "WaitForChild" since it is finding the first item. marioblast1244 113 — 6y
0
replaced line 5 and line 10 with recommandation, no change, same results. Decimaprism 65 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Try this;

for x,z in pairs(OptionMenu.Drop:GetChildren()) do
    z.MouseButton1Down:Connect(function()
        --local ObjItem = Bin.Background.Backpack:FindFirstChildWhichIsA("GuiButton")
        for i,v in pairs(Player.Backpack:GetChildren()) do 
            if v:IsA("Tool") then
                if v:FindFirstChild("Type") ~= nil and v.Type.Value == "Medical" then
                    DropItemEvent:FireServer(v)
                    Dropped:Play()
                    OptionMenu.Visible = false
                    break
                elseif v:FindFirstChild("Type") ~= nil and v.Type.Value == "Ammo" then
                    DropItemEvent:FireServer(v)
                    Dropped:Play()
                    OptionMenu.Visible = false  
                    break
                end
            end
        end
    end)
end
0
Line 1, what is Drop:GetChildren? Drop is a nil value. Decimaprism 65 — 6y
0
Woops, change line 1 to for x,z in pairs(OptionMenu.Drop:GetChildren()) do User#1007 6 — 6y
0
Ah, ya it dosent work either. Darn Decimaprism 65 — 6y
Ad

Answer this question