I want to delete just a Sword...
Thanks for helping out in advance.
function onTouched(hit) if hit.Parent:findFirstChild("Humanoid")~=nil then local user=game.Players:GetPlayerFromCharacter(hit.Parent) if user~=nil then local backpack=user:findFirstChild("Backpack") if backpack~=nil then local p=backpack:GetChildren() for i=1,#p do if p[i].className=="Sword" then p[i]:remove() end if p[i].className=="Tool" then p[i]:remove() end end end end end end script.Parent.Touched:connect(onTouched)
:Destroy() not :remove(). BOY WAKE UP IT'S NOT 2010. :FindFirstChild() not :findFirstChild()
You shouldn't use too many "~= nil" in your scripts. No duh every player has a backpack. Let me clean up your messy deprecated code.
script.Parent.Touched:Connect(function(part) local plr = game:GetService("Players"):GetPlayerFromCharacter(part.Parent) if plr then for _, child in pairs(plr.Backpack:GetChildren()) do if child.Name == "Sword" then child:Destroy() end end end end) -- clean.