Find a certain Parts Named a certain Name in Models in the Workspace

Ive been trying to create a script where itll scan the workspace find a folder named in this case
“Track” then look through the models in that folder and scan through every model for parts named “Sensor”.

So far all ive gotten is it to go through the folder and get the parts named sensor in the folder.
where as i want it to go through the folder search through every single model in the folder and look for
parts named “Sensor”.


Any help would be Appreciated.

1 Like

You came close.

  1. specify the path of Track.
  2. Filter all models in the folder.
  3. Find all parts with the name “sensor” in those models.
local track = workspace.Track -- path

-- Loop through all direct descendants (children).
for _,object in ipairs(track:GetChildren()) do
	-- Is the child a model?
	if object:IsA("Model") then
		-- Loop through all descendants of the found model.
		for _,descendant in ipairs(object:GetDescendants()) do
			-- Skip if the name is not sensor.
			if descendant.Name ~= "Sensor" then continue; end
			-- optional argument: if descendant:IsA("BasePart") then ... end
			descendant.Transparency = 1

Side note: This topic belongs to the #help-and-feedback:scripting-support category.


It works! Thank you for the help.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.