Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

how can i make a script that deletes a tool from playres backpack?

Asked by
MHaven1 159
8 years ago
script.Parent.ChildAdded:connect(function(h)
    local nt = h
    for i,v in pairs(game.Lighting:GetChildren()) do
        if nt.Name ~= v.Name then
            nt:Destroy()
        elseif nt.Name == v.Name then
            print("Right Tool!")
        end
    end
end)

i want this script to delete the new tool if it's name is not found in lighting. this script only deletes the new tool if there is 1 name in lighting if there are more then 1 names in lighting the new tool wont get destroyed even if its name is not found in lighting. please help me.

1 answer

Log in to vote
0
Answered by 8 years ago

Try this:

local sp = script.Parent
local lighting = game.Lighting

sp.ChildAdded:connect(function(child)
    local nt = child
    if lighting:FindFirstChild(nt.Name) then
        print("Right Tool!")
    else
        nt:Destroy()
    end
end)
Ad

Answer this question