I'm trying to make this script find the number of objects with a specific name in a model. How can I fix my script to do this? It currently works but gives the number of objects in the model not just the ones with a specific name. Thanks for any help!
local player = game.Players.LocalPlayer
local BUTTON = script.Parent
local FRAME = BUTTON.Parent.Parent.Parent.ShowFrame1
local NBox1 = FRAME.ColumnFrame2.BoxFrame2
local NBox2 = FRAME.ColumnFrame2.BoxFrame3
local NBox3 = FRAME.ColumnFrame2.BoxFrame4
local NBox4 = FRAME.ColumnFrame2.BoxFrame5
local HBox1 = FRAME.ColumnFrame3.BoxFrame2
local HBox2 = FRAME.ColumnFrame3.BoxFrame3
local HBox3 = FRAME.ColumnFrame3.BoxFrame4
local HBox4 = FRAME.ColumnFrame3.BoxFrame5
local htext1 = HBox1.TextLabel
local ntext1 = NBox1.TextLabel
local htext2 = HBox2.TextLabel
local ntext2 = NBox2.TextLabel
function check_Have()
local PACK = player:FindFirstChild("Pack")
local PACKTAB = PACK:GetChildren()
local name = FRAME.RowFrame2.TextLabel.Text
local obj = PACK:GetChildren()
local count = #obj
for index, child in pairs(PACKTAB) do
if child.Name == name then
local count = #obj -- Here is the problem. How would I say that the count is the number
-- of objects with the name- name (the variable called name not literally "name")
htext1.Text = count
end
end
print(count)
end

1 comment
Perfect answer, thank you