Getchildren problem

Im trying to make a scriptr so it gets the decendets of something and setting all of their transparency to , Thereis no errors btw

	for _, mesh in pairs(tree:GetChildren()) do
		if mesh:IsA("MeshPart") then
			mesh.Transparency = 1
			end
		end
1 Like

What exactly is the issue you’re having? If it’s that all the descendant MeshParts aren’t being set to transparent, try using tree:GetDescendants() instead of tree:GetChildren()

1 Like

you’ll need to use GetDescendants instead of GetChildren. GetChildren only returns the immediate children, while GetDescendants returns all descendants at all levels. Here’s your corrected script:

for _, mesh in pairs(tree:GetDescendants()) do
    if mesh:IsA("MeshPart") then
        mesh.Transparency = 1
    end
end
1 Like

thanks for the help, but for somereason the script does not conintue after it is finished?

1 Like

There is more scirpt after it btw

1 Like

Im trying to break the loop but it breaks the whole scritript and does not continue?

				for _, mesh in pairs(hit.Parent:GetDescendants()) do
					if mesh:IsA("MeshPart") then
						mesh.Transparency = 1
						break
					end
				end
				wait(2)
				for _, mesh in pairs(hit.Parent:GetDescendants()) do
					if mesh:IsA("MeshPart") and tree.Tree.Tree.Transparency == 1 then
						mesh.Transparency = 0
					end
				end
1 Like

When your breaking out of the loop there will only be one item that is transparent. Since the loop only runs one time.

1 Like

how would i fix that? Also when it breaks it does not coninue and wait 2 then do the next part

1 Like

Alright, so you are running the loop for every mesh inside a part. You check if it is a mesh then you set that mesh part to transparency to 1. Then you end the whole first for loop. The second for loops look if the mesh part is transparent witch it isent becuase you didn’t run the whole first loop. Then since it isen’t transparent it wont make it visible.

1 Like

Try this:

				for _, mesh in pairs(hit.Parent:GetDescendants()) do
					if mesh:IsA("MeshPart") then
						mesh.Transparency = 1
					end
				end
				task.wait(2)
				for _, mesh in pairs(hit.Parent:GetDescendants()) do
					if mesh:IsA("MeshPart") and tree.Tree.Tree.Transparency == 1 then
						mesh.Transparency = 0
					end
				end
1 Like

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