How to modify all parts inside models inside a model with a script

Im not really sure how to word this correctly but i am trying to change the transparency of all parts inside a model inside a model and there are unkown amount of models with unknown names. Is there any way to do that with a script? I have thought of it but i have only come up with very ineffective ways of doing it that wont work always (example bellow).

This is what i had in mind but there must be a more efficent way of doing it.

local models = game.Workspace.Model:GetChildren()

for i = 1,#models do
	if models[i].ClassName == "Model" then
		local models2 = models[i]:GetChildren()
		for i = 1,#models2 do
			if models2[i].ClassName == "Model" then
				local models3 = models[i]:GetChildren()
				for i = 1,#models3 do
					-- And would continue on and on for a long time..
				end
			elseif models2[i].ClassName == "MeshPart" then
				print("Mesh")
			end
		end
	elseif models[i].ClassName == "MeshPart" then
		print("Mesh")
	end
end
1 Like

Can’t you use GetDescendants?

local model = workspace.Model

for _,part in pairs(model:GetDescendants()) do
	if part.ClassName ~= "MeshPart" then
		continue
	end
	part.Transparency = 0
end

Just change 0 to the transparency you want

Edit: Changed the IsA guard clause to respect your original intention

2 Likes

I didnt even think of that for some reason but thank you for the solution

1 Like

It’s okay! Sometimes the obvious answer goes over our head!

If you have anymore issues don’t be afraid to make another post!

1 Like