script.Parent.ChildAdded:connect(function(g) wait(0.5) local newtool = g local oldtools = game.Lighting:GetChildren() for i,v in pairs(oldtools)do local oldname = v.Name if newtool.Name ~= oldname then newtool:Destroy() end end end)
so basically i want this script to delete any tool that is added in players backpack if it does not have the same name as 1 of the tools in lighting. but this script only deletes the tool if there is 1 tool in lighting if there are 2 or more tools in lighting this script will not destroy the tool that is added to the backpack. please help
Your script should work like this:
script.Parent.ChildAdded:connect(function(g) if not game:service'Lighting':FindFirstChild(g.Name,true) then g:Destroy() --put code logging the deletion here end; end)
Ideally, you should store all tools in ServerStorage
to prevent them being exploited into a Player's backpack, however LocalScripts cannot access this Service or any of its Descendant Instances.