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

Can anyone help with #game child search?

I want to search for the children of all game files. Its something I did a year ago and cant remember the exact code. Im still very new to .lua. So far I have this which I knew was wrong and wont work but it should be close...

for i,v in pairs, #game.Lighting.GetChildren() do tostring(v) print(v) end;

Any help in cleaning that up into real code?

1 comment

0

I do: for i,v in pairs(Game.Lightning:GetChildren()) do print(v.Name) end

3 answers

For future reference, please use Lua code formatting (the little Lua button above the text box on the editor.) when you post code. It makes it easier to see what's code and what's explanation.

It looks like you're trying to make a generic for loop using a numeric for style. This simply doesn't work.

First, pairs is a function, and it takes a Table as an argument. GetChildren returns a Table, but you have to call it as a method, using the : operator.

tostring(v) is unnecessary. print(v) will automatically call tostring() on v, since v is not a string.

Finally, and this is just a stylistic thing, unused return values (i in your code) are typically given an underscore (_) instead of a name, to indicate that they are not used.

for _, v in pairs(game.Lighting:GetChildren()) do 
	print(v)
end --Semicolons are not necessary in Lua 99% of the time.

3 comments

0

That does work but its only what i can see. The method i used a year ago came up with something more like https://github.com/ROBLOX/Core-Scripts/blob/master/CoreScriptsRoot/CoreScripts/PurchasePromptScript2.lua

0

Im trying to go a bit deeper into the code untill i reach what Roblox locked

0

Also i just found this through a scripting helpers link http://wiki.roblox.com/index.php/FindFirstChild dont know how that changed the full locked unlocked search

Pairs takes a table as an arguement, such as the table of contents of Lighting. I think tostring is just for numbers or something. Use v.Name.

for _, v in pairs(game.Lighting:GetChildren()) do
print(v.Name)
end

1 comment

0

"tostring" works on any value (and even 'nil'). "print" automatically converts its arguments to strings, perhaps via "tostring".

take away the comma after in pairs and it is :GetChildren() i think you have to add parentheses around #game.Lighting:GetChildren()

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