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

how do i use FindFirstChild() twice? [ anwsered ]

Asked by 4 years ago
Edited 4 years ago

so basically ive got a terrain generation script, the terrain is split up into chunk folders and i need to access a part from a chunk the code goes something like

Land:FindFirstChild(hpos..""..wpos..""..lpos):FindFirstChild(h..""..w..""..l)

just doing

Land:FindFirstChild(hpos..""..wpos..""..lpos) returns a value and ive double and triple cheaked it should work but it returns nil ?

help? its kinda needed for my game given the millions of parts when i generate the terrain fully

2 answers

Log in to vote
3
Answered by
Glacitron 239 Moderation Voter
4 years ago

From what I’ve understood you can try to Use 2 variables

local chunk1 = land:FindFirstChild(name of the chunk)
local objectinchunk = chunk1:FindFirstChild(name of the object)

Obviously you need to format it correctly and change the variables to whatever you want but that’s the basic idea.

0
sorry thats exactly what i did it returns nul LordOfSour 9 — 4y
1
Try and check the placement and where you put the Chunks and folders as firstchild only applies to the immediate child not anything under that, which would be done using descendants Glacitron 239 — 4y
0
ok thx LordOfSour 9 — 4y
1
Can you mark me as the answer please Glacitron 239 — 4y
0
i dont know how i would have already LordOfSour 9 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I believe in this case, what you are doing has an alternative:

local Child = Land[hpos.." "..wpos..""..lpos][h.." "..w..""..l]

I believe that should work, if it doesn't then looping is another way..

Also, maybe it is returning nil because there is no gap between "".

Also yes, what Glacitron said should work.

Answer this question