Need help with finding a tool in a player

I’m trying to make a button that deletes the tool a player is holding from the backpack and the startergear, but I’m having trouble with deleting it from those 2 and I was wondering if there was a way that I could use FindFirstChild() in different folders such as:

local tool FindFirstChildWhichIsA("Tool") -- the item the player is holding
player.Backpack.tool:Destroy() -- destroy the tool in the players backpack
player.StarterGear.tool:Destroy() -- destroy the tool in the startergear

it would be a great help if I could do this or there was some kind of alternative to it.

1 Like

try to make like this:

local tool = player.Backpack:FindFirstChildWhichIsA("Tool") -- the item the player is holding
tool:Destroy() -- destroy the tool in the players backpack
-- add next tool inside startergear
local tool2 = player.StarterGear:FindFirstChildWhichIsA("Tool")
tool2:destroy
-- To Make tool is destroy within 2 path and calling with a same time
-- 1: Backpack, 2:StarterGear
1 Like

the problem with this is that there are multiple tools in the backpack and startergear, the first tool variable was the one in the character since they can only hold 1 tool at a time

1 Like

StarterGear is a game service or Player Service??

1 Like

startergear is in the player service

1 Like

So what I currently have now is deleting the tool from the backpack, but not the startergear

script.Parent.MouseButton1Click:Connect(function()

local player = game.Players.LocalPlayer

local character = player.Character

local tool = character:FindFirstChildWhichIsA("Tool")

tool:Destroy()

local tool2 = player.StarterGear:FindFirstChildWhichIsA("Tool")

tool2:Destroy()

end)
1 Like

I have it all set up now but it’s all local so I’m going to add a Remote Event and see how that works out.

your code is fatally broken because the variable problems…

make a tool variable within a name because the server will destroy the two tools… so i recommended to make like this

local tool1 = character:FindFirstChild("The Powerness Tool Ever") -- example
local tool2 = player.StarterGear:FindFirstChild("THE GODNESS TOOL") -- example

examplebutton.MouseButton1Click:Connect(function() -- make the tool triggers
tool2:Destroy()
examplebutton2:Destroy()
end)

examplebutton2.MouseButton1Click:Connect(function()
tool1:Destroy()
examplebutton:Destroy()
end)

the problem with this is that it would only delete specific ones, which would make this not really work

local function ClearTools(...)
	for i,v in pairs(table.pack(...)) do
		if typeof(v) ~= 'Instance' then continue end;
		
		for name,instance in pairs(v:GetChildren()) do
			if not instance:IsA('Tool') then continue end;
			v:Destroy();
		end;
		
	end;
end;

--//Cleaning all using and inventory tools//--
ClearTools(Player.Backpack, Player.StarterPack, Player.Character);

You can try to use this.

Wouldn’t this delete every tool though?

this is more better than myselfs

Yes, but what you really want, just delete a specific tool or all them?

I’m trying to make the button delete the tool that the player is currently holding

All currently holding tools or some specific tool?

Just the tool that the player has equipped.

Just do it on server side.

PlayerCharacter:FindFirstChildWhichIsA('Tool'):Destroy()

it needs to delete from the backpack and starterpack too

that pretty complicated i think

i had it all working actually but it was all local and when i tried doing it on a remote event it didnt work