Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Performance Question On How To Address A Parent?

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
2
Answered by
lunatic5 409 Moderation Voter
5 years ago

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.

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. BunnyFilms1 297 — 5y
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. lunatic5 409 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

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. BunnyFilms1 297 — 5y
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. lunatic5 409 — 5y
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 lunatic5 409 — 5y

Answer this question