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

why does this only work with 1 tool? [unanswered]

Asked by
MHaven1 159
8 years ago
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

0
Pls use server storage not lighing to store models. User#5423 17 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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.

0
ok i will use server storage from now on MHaven1 159 — 8y
0
i am not fully english so please can you explain what you mean by 'put code logging the deletion here' MHaven1 159 — 8y
Ad

Answer this question