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.
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
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
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)
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)
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);