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.

local 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:

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

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

local Parts = {}

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

if Leg and Torso then
    table.insert(Parts,Leg)
    table.insert(Parts,Torso)
end

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

if condition then

end

in Javascript

if (condition) {

}
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