Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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.

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. User#20279 0 — 5y
0
^ no... Just GetDescendants.......... getChildren doesn't get all the children. greatneil80 2647 — 5y
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. User#20279 0 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

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)
0
doesn't seem to work, can the part named ET have something inside of it? User#22996 0 — 5y
0
Yes. As long as there are parts in the folder all will become a bit transparent. Well I thought so. namespace25 594 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

Answer this question