Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Dropping the Precise item Clicked?

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)

3 comments

0

what?

0

Try replacing both of the "FindFirstChild" on line 5 and 10 with "WaitForChild" since it is finding the first item.

0

replaced line 5 and line 10 with recommandation, no change, same results.

1 answer

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

3 comments

0

Line 1, what is Drop:GetChildren? Drop is a nil value.

0

Woops, change line 1 to for x,z in pairs(OptionMenu.Drop:GetChildren()) do

0

Ah, ya it dosent work either. Darn

This discussion is preserved as it was. New answers, comments, and votes are closed.