How to get children with a certain name?

local Items = #Player.Backpack:GetChildren()

Say I wanted “Items” to be just the children of the Backpack with a certain name.

(To clarify, I want this to just count the number of instances with the same name.)

What’s an efficient way to do this?

Thanks! :slight_smile:

1 Like

You can iterate through the children.

local items = Player.Backpack:GetChildren()
local nameCount = 0

for index, child in ipairs(items) do
	if child.Name == "WhateverNameHere" then
		nameCount += 1
	end
end

print(nameCount)
5 Likes