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

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

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

✓ Accepted answer

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.

2 comments

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

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.

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