Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What does script.Parent.Parent.Parent mean? I have a trouble with understanding this code

For example:

local part = script.Parent.Parent.Parent.Part

I've seen a code with this and when I tried to remove Parent.Parent so it was just script.Parent.Part it just didn't work. Then i knew that it needs to be there but I don't know why. So can someone explain me why there are multiple Parents?

1 answer

✓ Accepted answer

By itself, script.Parent is equivalent to the instance that the script is inside of. However, for example, if the script was inside a part that was inside of workspace, you can go script.Parent.Parent to get the workspace. If there was a part inside workspace called Part, you could then go script.Parent.Parent.Part to get the part.

Essentially, all your code is doing is getting the parent of the parent of the parent of the script, and then getting the part inside of it.

1 comment

0

Thank you so much!

This discussion is preserved as it was. New answers, comments, and votes are closed.