Simple question about script.Parent

Does script.Parent automatically wait for child? I just tried this and apparently you can swap out a wait for child(the part) with script.Parent as long as the part is the parent of a script. If someone can confirm this, I will mark your answer as solution. Thank you!

No, script.Parent does not automatically wait for the parent to load.

However, WaitForChild should be used if there’s any chance the parent (or any part of the hierarchy) isn’t immediately available.

How are my parts instantly available into the workspace? I even tested find first child and it didn’t return nil either. This is strange.

When you parent an object to the workspace, it is immediately part of the scene, and any script that runs after this will be able to reference it right away. For example:

local newPart = Instance.new("Part")
newPart.Parent = workspace

PS: here’s an example if you need:

local newPart = Instance.new("Part") -- Create a new part
newPart.Parent = workspace -- Parent it to workspace

-- Check for availability immediately after parenting
local foundPart = workspace:FindFirstChild(newPart.Name) -- This will find the part
print(foundPart ~= nil) -- This will print true, meaning the part was found

1 Like

well yes but actually no, the script doesnt run until it is loaded in, which it won’t be until its parent is already loaded in

1 Like

This is spot on! I actually ran a child added function to test this and sure enough you actually don’t need to wait for child on parts that are immediately part of the scene. Thank you so much! :smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.