Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

1 comment

0

You could accept my answer too, lol

1 answer

✓ Accepted answer
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

1 comment

0

Alright thanks! Ill use It right now!

This discussion is preserved as it was. New answers, comments, and votes are closed.