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

How do I list 2 or more Childs(FindFirstChild)?

Asked by 4 years ago
Edited by Gey4Jesus69 4 years ago

very easy to solve, i just got back into lua.

1local Findit =  (script.Parent.Parent:FindFirstChild("LegTrue")),(script.Parent.Parent:FindFirstChild"TorsoTrue")
0
Weird Glitch going on, Top line (my words) aren't part of the script, Sorry! snipperdiaper 120 — 4y
0
two different variables?? why are you trying to combine them? Gey4Jesus69 2705 — 4y
0
and it wasn't a glitch. you put four spaces before your description, so it considered it a code block Gey4Jesus69 2705 — 4y
0
@Gey4Jesus69, yes I am trying to use one (local) variable to collect two of these parts (TorsoTrue, As well as LegTrue) snipperdiaper 120 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Just store them in two separate variables:

1local Leg = script.Parent.Parent:FindFirstChild("LegTrue")
2local Torso = script.Parent.Parent:FindFirstChild("TorsoTrue")

If you truly need them in one place, you can store them in a table, like so:

1local Parts = {}
2 
3local Leg = script.Parent.Parent:FindFirstChild("LegTrue")
4local Torso = script.Parent.Parent:FindFirstChild("TorsoTrue")
5 
6if Leg and Torso then
7    table.insert(Parts,Leg)
8    table.insert(Parts,Torso)
9end

Also note that parentheses do not have to wrap statements, like in Javascript and similar languages. For example, in if statements, you do not have to wrap the conditions.

in lua

1if condition then
2 
3end

in Javascript

1if (condition) {
2 
3}
1
Thank you so much, trying to figure out how I can lower the amount of lines in my code/ make it look nicer! thanks so much snipperdiaper 120 — 4y
1
https://gyazo.com/db5945297faf59c9066db608691ecee8 Might be a stupid project but u helped :) snipperdiaper 120 — 4y
Ad

Answer this question