a = game.Workspace:GetChildren() for i = 1, #a do if (a[i].className == "Part") then a[i].Reflectance = 1 else return end end
Script from wiki
I dont get any of the script at all. Why is there a #a and then what does a[i] mean? If you could translate the whole thing that would be great. Also how would i use GetChildren() in other scripts?
-Thank you for reading
a = game.Workspace:GetChildren() for i = 1, #a do if (a[i].className == "Part") then a[i].Reflectance = 1 else return end end
All ROBLOX instances within the service (workspace) are returned in a list, which is assigned to a
. a then becomes a table containing the list.
the length operator (#) on the second line followed by a table returns an integer that represents just the index of the last value of the table. In other words, the total number of values in said table.
a[i] just simply means accessing the value located at index i
of table a
. Since all values have a unique corresponding index, and that indices are integers, we can only get the value using the index -- because we want the value, and not the number.
For a much easier understanding of how it all works, here's a little cleaner version of the snippet you've provided.
list = workspace:GetChildren() for index = 1, #list do if list[index].className == "Part" then -- if value at index is a "Part" then -- set its reflectance to "1" list[index].Reflectance = 1 else return end end
Using the call "GetChildren()" is simple. It says what it does. It literally finds and gets the childs of a Parent. You can have an argument in it, or leave it blank. Here is an example:
game.Workspace:GetChildren()