{CLOSED} How do I destroy all players gear

Hello, ExoticTwix im trying to make a button give player pistol (wich it is) though what im trying to do is when it is clicked it deletes anyother gear/tool from players Backpack then wait .1 or 1 then give the player the pistol. SO then they can only have one. Line 5 is the problem please help me :slight_smile:

You are Destroying a table which is not possible, use plr.Backpack:ClearAllChildren() in the function instead. Remember this is still not a good idea and you should do something like:

for i,v in pairs(plr.Backpack:GetChildren()) do
	if v:IsA("Tool") then
		v:Destroy()
	end
end
1 Like

For some reason the tool is deleted sometimes is there a way so it always works

I am confused on what you mean, my code I sent should work 100% of the time.

Some proof

I sent the video to you for it not working when equiped

When its equiped and clicked again it duplicates 1 so theres 2

What is your idea of your inventory, do you want players to equip multiple tools but not multiple of the same?

1 Like

Yes so you can equip 1 gun at a time

I guess you could check if the tool already exists instead of destroying it.

if plr.Backpack:FindFirstChild("Handgun") == nil then
	script.Handgun:Clone().Parent = plr.Backpack
end

Something like this should get the job done better.

2 Likes

Opps sorry i messed up the script YES IT WORKS thanks alot

1 Like

I have one last question. Im going to be adding other weapons to the inventory. How would I destroy the other weapons in Backpack?

other then the new one …

Add plr.Backpack:ClearAllChildren() before the FindFirstChild part.

What do you mean before FindFirstChild

for i,v in pairs(plr.Backpack:GetChildren()) do
	if not v.Name == "Handgun" then
		v:Destroy()
	end
end

Or this should work too, you can add that anywhere in the function.

This doesent work for me…

if player.Character:FindFirstChildOfClass(“Tool”) then
player.Character:FindFirstChildOfClass(“Tool”):Destroy()
end

1 Like

where am i putting this in…

In the Ipairs loop. 30chars ssss