What im talking about is is it possible for a script to detect all children from a model. For example: Lets say the code is FindChildren
1 | local childs = script.Parent.FindChildren |
2 |
3 | childs.Transparency = 1 |
4 | childs.canCollide = true |
So now, all the children from the Model now have a transparency of 1 and Collision. Is there another feature for that?
There is a function for this already.
1 | local children = script.Parent:GetChildren(); -- This is gathering all of the children in script.Parent into an array (i.e., children = {script, textLabel, etc.}) |
2 |
3 | for i,v in pairs (children) do -- The for loop is used to sort through the array in order and we can manipulate parts as need be. The variable i shows the number in the array that the entry is, whereas the v variable is for the part itself. Given how v is an object we can't just do print(v) we would need to do print(v.Name) to see what v's real name is. |
4 | v.Transparency = 1 ; -- Setting the transparency of object v to 1 |
5 | v.CanCollide = true ; -- Setting it so that v CanCollide with other blocks |
6 | end ; |
This will make every part in the scripts parent so they can collide and they are invisible. If you are looking for a specific part you can use this function
1 | local child = script.Parent:FindFirstChild( "Sphere" ); -- This finds the first child in script.Parent with the name of "Sphere". Now you can do whatever you want to it. |
If this helps, please accept this answer.
Yes. You tried, and that's good. However, the correct function to use is :GetChildren(). This will return an array - or table - of children.
To find a specific child, you can use :FindFirstChild(name). If the child is not found, it will return nil
.