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?
✓ ANSWER ACCEPTED
How to get all children and do something to them?
2 answers
✓ Accepted answer
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
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
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
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.
Thank you, this worked! I never knew about in pairs loops before but this is great!