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

Performance Question On How To Address A Parent?

Simple question. I am working with UI right now and I am wondering which one is more efficient/recommended to be used when calling the parent? Both do reference the same parent.

local Button = script.Parent.Parent:WaitForChild("ReCenterMap")

or

local Button = script.Parent

2 answers

✓ Accepted answer

I am not exactly sure of what you are trying to accomplish here. The second line of code would be much more simple and just as efficient as the first line. The first line of code just overcomplicates things. If I am correct, there is no need to use WaitForChild() to wait for the parent of a script. I'm fairly certain that if the script has loaded in, the parent of the script has too.

2 comments

0

That was the answer I was looking for. Thanks. Just to clarify, I am just wondering because I am doing a MouseButton1Down on a TextButton to open another GUI.

0

No problem! And yeah, I figured that's what you were trying to do because you said you were working with UI. Also, are you new to Lua? I'm not too experienced myself, but when I first started, I was a bit confused by WaitForChild() and UI as well.

That makes no sense. What are you trying to accomplish?

3 comments

0

I am assigning the parent to a "word" (not sure the correct terminology) so that I do not need to repeat the same thing.

0

The terminology you are looking for here is "variable". That is what you would call assigning a simpler (and often shorter) name to something so you don't have to type a lengthy amount of information just to call for a single object. You can think about it like algebra. For example, in some algebraic expressions, you would use the variables x and y. Let's say x = 4.

0

Now, whenever I call for x, it is known that I am referring to the number 4. And if y is to equal, let's say, 7, then whenever I call for y it is known that I am referring to the number 7. For more information on variables, you can visit this robloxdev article: http://robloxdev.com/articles/Variables

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