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

Could i get help with GetChildren() please?

Asked by 9 years ago
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

2 answers

Log in to vote
3
Answered by
ImageLabel 1541 Moderation Voter
9 years ago
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
0
FAK! I HAD A WHOLE ANSWER AND I REFRESHED! I HAD MORE EXPLAINATION THAN YOU!!! Dang it. EzraNehemiah_TF2 3552 — 9y
0
Ty for the help ScriptPrac 5 — 9y
0
If you understand and have no further questions, accept answer please :D ImageLabel 1541 — 9y
1
good answer image. +1 for you. give me cookies now DigitalVeer 1473 — 9y
View all comments (2 more)
0
How I accept answer I don't know sorry I'm new to this(noob) ScriptPrac 5 — 9y
0
It may be better to use a 'Generic For' loop for these types of situations. :P TheeDeathCaster 2368 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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()

0
What about this part of the script for i = 1, #a do if (a[i].className== "Part" ) then a[i].Reflectance= 1 else return end end ScriptPrac 5 — 9y
0
Ty for the help ScriptPrac 5 — 9y

Answer this question