local Tools = {}
for i,v in pairs(player.Backpack:GetChildren()) do
if (v:IsA("Tool")) and (v.Name == "ToolToRemote") then
table.insert(Tools, v)
end
end
Tools[1]:Destroy()
Put in a print() function into the code to see if it somehow runs multiple times and show us the output. I really don’t see how it could remove multiple tools by running just once.
If you want a specific instance to be deleted then you need to store that instance itself as there is no other way to separate two identical instances without storing one. For example:
local MyTool = ReplicatedStorage.Gun:Clone()
wait(10)
-- ok gun needs to go away now
MyTool:Destroy()
An example of how you would achieve this in a proper way though:
local PlrWeaponsToRemove = {}
function OnChar(Player,Character)
local MyGun = game.ReplicatedStorage.Gun:Clone()
MyGun.Parent = Player.Backpack
PlrWeaponsToRemove[Player.Name] = {
MyGun,
}
wait(5)
for i,v in ipairs(PlrWeaponsToRemove[Player.Name]) do
v:Destroy()
end
end
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
OnChar(Player,Character)
end)
end)
Okay, so in my script i actually have 2 tools checker
if player.Backpack:FindFirstChild("ToolToRemove") then
player.Backpack:FindFirstChild("ToolToRemove"):Destroy()
end
if player.Character:FindFirstChild("ToolToRemove") then
player.Character:FindFirstChild("ToolToRemove"):Destroy()
end
And when i hold one while triggering the tool remove it removes multiple of them
Oh okay I understand now.
You could first check if the player is holding it, if yes then remove it, otherwise (elseif statement) check if it’s in the inventory. This way it won’t remove both the one in their hands and in the inventory.
if player.Character:FindFirstChild("ToolToRemove") then
player.Character:FindFirstChild("ToolToRemove"):Destroy()
elseif
player.Backpack:FindFirstChild("ToolToRemove"):Destroy()
end