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

How to get all children and do something to them?

Asked by 2 years ago

Hi, I have a script which I use where whenever the parent is touched, it makes all children visible. I've looked at GetChildren() and and GetDescendants() but they're read-only, and I need to be able to make the children transparent. Any help?

2 answers

Log in to vote
0
Answered by 2 years ago

This is simple, you only need to use an In Pairs loop and call GetChildren()/GetDescendants instead of a table, your script will automatically make all children visible, something like this:

GetChildren()example:

for i, v in pairs(Parent:GetChildren()) do
    --Your script, "v" would be the instance your making visible
end

GetDescendants() example:

for i, v in pairs(Parent:GetDescendants()) do
    --Your script
end

Hope you know what an In Pairs loop is, if not watch this AlvinBlox video, he explains it pretty well

0
When doing GetChildren() and GetDescendants() it turns inside of the parentheses to a table like this for i, v in pairs({values}) do  end     and inside the table is all the children or descendants. MarkedTomato 810 — 2y
0
Thank you, this worked! I never knew about in pairs loops before but this is great! Dothemariobowp9 24 — 2y
Ad
Log in to vote
1
Answered by 2 years ago

Hello.

Im not sure what exactly your going for but this should work. reply if it doesnt. i maybe able to help again.

You probably want to use a loop. more specifically an in pairs loop this should do the trick:


local transparency = 0 -- 0 will make it visible while 1 will make it invisible local part = game.Workspace.Part -- change this to the part that will be touched part.Touched:Connect(function(hit) -- we put hit there incase we ever need the player in the future for i,v in pairs(part:GetChildren()) -- loop through all the children v.Transparency = transparency -- change the childrens transparency end end)

There may be typos/capitalization errors. i didnt use roblox studio to write this

Answer this question