How do I get every single part that shares this name?

Okay, so I am trying to make a script that disables collision on windows to prevent a bit of lag, now I have the script except it just looks threw workspace with only finds 1. The rest of the windows are in separate models how do I get every single one of them?


local Workspace = game.Workspace

for i, v in pairs(Workspace:GetChildren()) do
	if v.Name == ("Window") then
		coroutine.wrap(function()
			for i = 0, 1, .2 do
				print("Found window")
				v.CanCollide = false
				v.CanTouch = false
				
				wait(.5)
			end
		end)()
	end
end
1 Like

:GetDescendants

This should do what you require!

2 Likes

Let me try it! Thank you so much!

1 Like

Is this right? Because it doesn’t work


for i, v in pairs(Workspace:GetDescendants()()) do
	if v.Name == ("Window") then
		coroutine.wrap(function()
			for i = 0, 1, .2 do
				print("Found window")
				v.CanCollide = false
				v.CanTouch = false
				
				wait(.5)
			end
		end)()
	end
end

Can you show a picture of what your Window models and the stuff inside them look like in your explorer

1 Like

Here you go:

image

1 Like
for i,v in pairs(workspace:GetDescendants()) do
	if v.Name == "Window" and v:IsA("BasePart") then
		v.CanCollide = false
	    v.CanTouch = false
	end
end

Or you can use this, same thing just scans the Academy folder instead of Workspace:

for i,v in pairs(workspace.Academy:GetDescendants()) do
	if v.Name == "Window" and v:IsA("BasePart") then
		v.CanCollide = false
		v.CanTouch = false
	end
end
1 Like

Thanks, but what about if the model is named “Window” but I want the parts inside no collide too, some are parts named Windows and some are models with parts and union

2 Likes

I would suggest using the Collection service for this along with a neat plugin called Tag Editor to mark the objects you want to access, would make the process easier.

1 Like
for i,v in pairs(workspace:GetDescendants()) do
	if v.Name == "Window" and v.ClassName == "Model" then
		for i,v in pairs(v:GetDescendants()) do
			if v:IsA("BasePart") then
				v.CanCollide = false
				v.CanTouch = false
			end
		end
	end
end

This just finds all models in the workspace called Window and then makes all parts inside them noncollidable (doing full-scale workspace scans like this is quite bad practice and it would be better if you just put all the window parts in one folder for efficiency)

1 Like

GetDescendants also searches for objects inside a object, so you don’t have to worry about that.

1 Like

Ohh I think I understand. But shouldn’t that and be or?

1 Like

Nope, that script would work fine at finding anything inside models called Window, just test it and see how it goes

1 Like

Works! Ty for the help! I understand now

1 Like