I am wanting to know how to script better. I want to know which is better.
Part:WaitForChild("Parent") or Part.Parent
workspace.Part or game.Workspace.Part
I am wanting to know how to script better. I want to know which is better.
Part:WaitForChild("Parent") or Part.Parent
workspace.Part or game.Workspace.Part
:WaitForChild is just used if the .Part doesn’t work that means if its used by a client. workspace and game.Workspace are the same.
These are the best you can use.
Part:WaitForChild("Parent") makes no sense whatsoever… As pointed out below it is possible, but I still don’t think it’s a good idea to name child parts the same as a property of the parent, as it’s confusing to read and forces you to use another method to access them
Direct indexing using . is faster, however, it will throw an error if the child hasn’t yet loaded, so this is when you would use WaitForChild(), but you should only use it when you are expecting something to load else it could be waiting indefinitely.
WaitForChild().
Part:WaitForChild("Parent") searchs for a part called “Parent” whose parent is “Part”, Part.Parent gets the parent of Part.Part["Parent"] too and it returns same than Part.Parent.pcall() if it’s able to error.Workspace” is a property of “game”, so it (should) never error if you put game.Workspace on a script. Still I prefer using “workspace”This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.