#Can someone please what WaitForChild() means and does?

45 messages · Page 1 of 1 (latest)

earnest garden
#

Sorrry if this is a stupid question but im really trying to learn some lua! Please dont flam me if this is a stupid question

craggy stirrup
#

it waits for a child

earnest garden
#

What is a child?

#

lol

craggy stirrup
#

for example, lets say i have a part in workspace named "Part"

then, lets say i have this server script:

local part = workspace.Part

print(part.Position)

This is probably going to return an error

#

theres a couple specifics which i forgot 💀 but the script wont recognize a child of workspace named "part"

#

thats because the script will run before the part is loaded

earnest garden
#

Oooh

craggy stirrup
#

instead, if i did

local part = workspace:WaitForChild("Part") --looks for a child of workspace named "Part"

print(part.Position)
#

that would work

craggy stirrup
earnest garden
#

That makes so much sense now thank you bro🙏

craggy stirrup
#

crude drawing but a child is an instance that is parented under another instance

#

so in my previous example, workspace would be the parent of Part

#

all instances can only have 1 parent

#

but instances can have any number of children

#

so although workspace would be the only parent of Part, workspace would be a parent to multiple things (baseplate, spawn, etc)

#

i just took this picture from another post but here, SprintBars has 6 children

#

you can barely see that SprintBars is a child of another thing

earnest garden
#

Aah yes i see

#

I get it now

#

but how do you know when to use it?

craggy stirrup
#

thats a little more complicated

#

it goes into client server boundaries and replication

#

if your starting off, i wouldnt learn those

#

yet

worn scroll
#

yea

craggy stirrup
#

but for now, just try it out and if theres an error on that line, try using wait for child

#

its a bit over the top but it works

earnest garden
#

Okay thanks man I really appreciate the help

#

🙏

craggy stirrup
#

just remember that you should use wait for child in places where something loads before the script itself

craggy stirrup
dry lily
earnest garden
dry lily
#

like learn how to script.

earnest garden
#

What do you think im trying to do? 😭

#

Im trying to understand what im actually typing

#

lol

dry lily
#

just check roblox docs first

#

that could have answered your question

earnest garden
#

Sorry

ivory dome
#

This should not have been 44 messages