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

Question about 2 lines of code in roblox core gui module scripts?

Asked by
imKirda 4491 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

So i've been browsing roblox core gui scripts and found a script with these 2 lines:

local RobloxGui = CoreGui:WaitForChild("RobloxGui")
local Utility = require(RobloxGui.Modules.Settings.Utility)

I was confused, they use :WaitForChild() on the RobloxGui, but do not use it on the Utility variable. How does that work? I've been doing a lot of research and i know that WaitForChild waits for the instance and not it's children so why don't they use it on the utility module? Does it have to do something with the point that is it core script or modules replicate like that?

Thanks in advance, kirda

1 answer

Log in to vote
0
Answered by 3 years ago

All modules are accessed by calling the require() function. Utility is a module, so it is required to use that function to access it. However, RobloxGui is not a module, so :WaitForChild() is used to pause to script until is is in the CoreGui.

Hope this answers your confusion.

0
I think i get you but could you please explain it a little bit more? From what i got, the script waits for the core gui for the module to load? Is this what you mean? Thanks imKirda 4491 — 3y
0
The script first waits for the RobloxGui, inside of the CoreGui. Then, it defines the variable 'Utility' as the module. Be aware this script DOESN'T wait for the module. If it's not there, it would simply return an error. NinjaMandalorian 252 — 3y
Ad

Answer this question