Help on detecting multiple parts that have the same name in the workspace

I’m trying to detect parts with the same name as I am cloning parts and I want to be able to change properties. I don’t know the direction that I need to head.

Help is appreciated!

You would have to loop through all parts in the workspace, then use an if statement to check the name.


for _, part in ipairs(game.Workspace:GetChildren()) do
    if part.Name == "NAME" then
        -- Do stuff

Here’s a fancier way to do it:

local function getInstancesWithName(parent: Instance, name: string): {Instance}
	local results = {}
	while true do
		local x = parent:FindFirstChild(name)
		if not x then break end
		table.insert(results, x)
		x.Parent = nil
	for _, result in pairs(results) do result.Parent = parent end
	return results 

print(getInstancesWithName(workspace, "SpawnLocation"))

If you want to access ALL the possible objects then use workspace:GetDescendants()

for _, Object in workspace:GetDescendants() do
   if Object.Name == "foo" then
      -- do property change here