Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Could i get help with GetChildren() please?

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

✓ Accepted answer
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

6 comments

0

FAK! I HAD A WHOLE ANSWER AND I REFRESHED! I HAD MORE EXPLAINATION THAN YOU!!! Dang it.

0

Ty for the help

0

If you understand and have no further questions, accept answer please :D

1

good answer image. +1 for you. give me cookies now

0

How I accept answer I don't know sorry I'm new to this(noob)

0

It may be better to use a 'Generic For' loop for these types of situations. :P

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

2 comments

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

0

Ty for the help

This discussion is preserved as it was. New answers, comments, and votes are closed.