Attempt to index nil with 'WaitForChild' [For Plugin]

Hey, I am scripting a plugin that features GUI, and when I want to define each frame. Every time I try to do that though, it doesn’t work. Here is the script:

I don’t know if I should just define the variables manually every single time, but if I have to I will.

On which line do you get this error exactly? We’d need a bit more info

WaitForChild returns nil when a timeout is set, and the set amount of time has passed. Just ignore the timeout parameter, it’s optional.

1 Like

Sorry about that, line 11


Yes but when I do that it just says attmept to index nil with (the thing I’m trying to get)

Again, WaitForChild returns nil when you set a timeout and the script has waited enough time. If 10 seconds passed, the variable gui is just nil, non-existent, even if the object itself has been added 10 seconds after. Thus, running gui:WaitForChild() or other functions means nil:WaitForChild(), causing the error you mentioned.

Just do local gui = script:WaitForChild("mainGui") without the timeout.

Infinite yield possible on 'user_plugincode.lua.Script:WaitForChild("mainGui")'  -  Studio

Now this error is showing

This is expected behavior. You don’t have mainGui under your script.

Then how am I supposed to make the GUI show up? lets just continue in dms

Oh, you saved as .lua I think. That’s a script file, not a Roblox model file. Try .rbxm.

1 Like

also I do have mainGui under the script

would i just have to publish it and it is still saying infinite yield on mainGui

The .rbxm option can be found by saving it as a local plugin. If you want to publish, maybe try grouping it first.

I wish it showed as an option but it isn’t.


There’s the Save as type dropdown menu. Click that, select .rbxm. Merely adding the extension name won’t work unless you have “All types” selected.

When I press the dropdown it does not show “all files” or “.rbxm” I can try doing it manually but I don’t know why its doing this

Hmm, that’s weird. Group (Ctrl+G) the script, save again, and see what happens.

It isn’t showing the option to save as local plugin for a group (it’s faded)


this is what happened when i tried manually doing it

How did you group your script? The test model I have is valid:


Ok I’ll try that (should I do that with the GUI?)