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

Can anyone help with #game child search?

Asked by 9 years ago

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?

0
I do: for i,v in pairs(Game.Lightning:GetChildren()) do print(v.Name) end unix_system 55 — 9y

3 answers

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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.
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 oEl3V3No 5 — 9y
0
Im trying to go a bit deeper into the code untill i reach what Roblox locked oEl3V3No 5 — 9y
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 oEl3V3No 5 — 9y
Ad
Log in to vote
0
Answered by
funyun 958 Moderation Voter
9 years ago

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
0
"tostring" works on any value (and even 'nil'). "print" automatically converts its arguments to strings, perhaps via "tostring". chess123mate 5873 — 9y
Log in to vote
-1
Answered by 9 years ago

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

Answer this question