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

How to check and see If the player has a certain amount of Items Inside of there backpack?

Asked by 2 years ago

Hello!

I am making a crafting system where If you have 5 of the same certain Items (Example: Sticks) then you can create something else, like a sword or something, the problem Is that I don't know how to check It the player has more than 1 certain Item for It to be crafted

0
You could accept my answer too, lol Ziffixture 6913 — 2y

1 answer

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
2 years ago
Edited 2 years ago
local function getChildrenNamed(name, amount, parent)
    local children = {}
    local childrenLeft = amount

    for _, child in parent:GetChildren() do
        if child.Name == name then
            table.insert(children, child)

            childrenLeft  -= 1
            if childrenLeft == 0 then
                break
            end
        end
    end

    return #children == amount, children
end

-- ...

local gotAll, children = getChildrenNamed("Sticks", 5, backpack)
if gotAll then
    -- Delete children, yada-yada
end
0
Alright thanks! Ill use It right now! imnotaguest1121 362 — 2y
Ad

Answer this question