Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to select all parts named "ET" and make them transparent when clicked button gui?

I'm trying to figure out how to make all parts named "ET" in workspace transparent 0.3 when a text button gui, I used a onClick function for when the button was clicked i don't know if that's why or if its the code i got for selecting all parts from here.

this is my script:

local name = "ET"

function onClick()

local function Modify(part)

part.Transparency = 0.3 end

local function recursive(obj) for _, child in pairs(obj:GetChildren()) do if (child.Name == name) then Modify(child); end recursive(child); end end recursive(workspace);

end

I dont know what's wrong with it. If you can help I thank you very much.

3 comments

0

You can use :GetDescendants() instead of :GetChildren() as :GetDescendants() gets every single object in workspace, unlike :GetChildren() which only gets the ones directly parented to workspace.

0

^ no... Just GetDescendants.......... getChildren doesn't get all the children.

0

^ I think you misunderstood. I was trying to say that GetDescendants() gets everything, not both. I’ll reword my last comment to be more clear. Also, GetChildren() does kinda get all the children if you think about it.

2 answers

Try this Creating a folder in workspace named ET then

script.Parent.MouseButton1Click:Connect(function()
	local folder = workspace.ET
	for _,v in pairs(folder:GetChildren()) do
		if v:IsA("Part") or v:IsA("BasePart") then
		v.Transparency = .3
 	end
	end
end)

2 comments

0

doesn't seem to work, can the part named ET have something inside of it?

0

Yes. As long as there are parts in the folder all will become a bit transparent. Well I thought so.

You can just check the names of every part in workspace to see if their name is "ET" and that they are a basepart, if so, you make it transparent

for _,v in next,workspace:GetDescendants() do 
	if v.Name == "ET" and v:IsA("BasePart") then
		v.Transparency = 1
	end
end

well this method certainly works for the lazy,I would recommend making a folder for all things named ET and loop through that folder

for _,v in next,workspace.ETs:GetChildren() do
	if v:IsA("BasePart") then
		v.Transparency = 1
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.