Check For New Tool In Backpack (ChildAdded)

I want to know when a player gets a new item, so I used ChildAdded to check when a new tool goes into the backpack.

But when you equip and unequip a tool, it goes back into the backpack, triggering the ChildAdded event… Falsely activating the new tool function.

I tried doing a variable that is within every tool to see if it’s a new item or not, but that seems a little hacky and I feel like there are better ways.

Any ideas?

2 Likes

you could create a table of all tools that have been added and check if the child added is part of it

I’ve written a quick script that should work (might be a couple small problems because I’ve written it on the spot)

local Tools = {}

for i,Tool in pairs(player.Backpack:GetChildren()) do
    table.insert(Tools,#Tools+1,Tool)
end

player.Backpack.ChildAdded:Connect(function(child)

    local AlreadyHas = false

    for i,v in pairs(Tools) do
        if v == child then
            local AlreadyHas = true
        end
    end

    if AlreadyHas = false then
        --New tool has been added
        table.insert(Tools,#Tools+1,child)
    end
end)
3 Likes

Ah, I was afraid I was gonna have to do some table stuff.
Alrighty.

2 Likes