Plugin can't find itself

I am trying to create my first plugin, all is going well except for when it comes to requiring a module script or displaying a gui. I can’t seem to ‘package’ these along with my plugin, because my plugin can not find itself.

Any time I use script.Parent inside of my plugin script (which is a server script in ServerScriptService, that I have selected and did ‘Save As Local Plugin’ on) the script returns the message 'attempt to index global ‘script’ (a nil value)

I have looked at many examples online that use script.Parent, so what am I doing wrong?

Thanks

2 Likes

Sometimes errors will tell you that the first object in the list cannot be found when it’s actually something further along the path. If your script is not inside a folder or model, I believe it’s parented to nil when used as a plugin. Hence this error is telling you that it’s parent is nil, not that the script is. If you put the script in a folder, then whatever else you want to access in that folder too, you should be able to access that.

If you just want to access serverscriptservice, just do game.ServerScriptService, remember that it doesn’t matter where the plugin script is in the explorer panel when you upload the plugin, it does not go there when the plugin is used.

I have tried saving the plugin in a folder, and in a model, and those varieties from serverscripts, from workspace and from serverstorage, just to see if anything changed.

The only thing I see that makes a difference is if the plugin script is a ‘local script’, then it can find itself, however, the wiki says this… “LocalScripts do not execute when a plugin is loaded. Any plugin logic must be contained within Scripts (or ModuleScripts required by the plugin’s Scripts.”

Also, the error can not be anything farther down in my plugin, as the plugin functions perfectly, the only thing that makes the error happen is if I add … print(script.Parent)

As I said, this will work on a local script, but not a server script.

When you put it in a folder / model, you are uploading the folder / model as the plugin, not the script, right?

Can you also send the hierarchy of your plugin along with: the full error and the line of code which is erroring.

Yes, when putting in a folder or model, i right click on the folder or model and select the ‘Save As Local Plugin’ option, which saves it, and refreshes the plugin, causing it to execute, and getting the same error.

Open a new studio tab every time you update the plugin so that you’re 100% sure it’s using the new version and try that again.

Ok, I created a new plugin script, this is its contents…
local toolbar = plugin:CreateToolbar(“Test”)

I save and it refreshes, and I see an empty plugin container in the toolbar, and no errors, same happens when I open a new studio

Then I went and changed the code to this…
local toolbar = plugin:CreateToolbar(“Test”)
print("Server ",script.Parent)

I save and it refreshes, and I get this error…
11:16:33.184 - Test.lua:2: attempt to index global ‘script’ (a nil value)
11:16:33.185 - Stack Begin
11:16:33.186 - Script ‘Test.lua’, Line 2
11:16:33.187 - Stack End

So I open a new studio, and this error immediately pops up.

Is this script inside a model / folder? What is the script.Parent you are trying to reference?

I just tried the above in a model and a folder still the same, but the problem is not the .Parent property, even if I put …
print(script)
or, I’ve tried…
print(script.Name)

I still get the same error, that script is nil

This is the tutorial I used to create my plugin, although they never reference the script in the tutorial…
http://robloxdev.com/articles/Intro-to-Plugins

Plugin scripts are parented to nil, therefore they don’t exist when you print them. If you look at your error:

You can see that the script has no path, it is just ‘Test.lua’. I’ve got multiple plugins that use models with other instances inside them which I reference through script.Parent, so I know that it does work.

It is possible there is a real bug here but it’s really unlikely since a lot of plugins work this way so there would be a lot more forum posts.

Are you pressing this each time? image

Perhaps the issue is that the ‘Save As Local Plugin’ is something new? Do plugin developers use this, or do they simply publish when they save?

1 Like

That’s definitely possible, perhaps it runs in an external environment or something and therefore you can’t reference the script like that.

If you see in the tutorial that I was following, it have me using the ‘Save As Local’ instead of publishing, I think this might be the issue, let me try to actually publish the plugin

1 Like

Oh my goodness… plugins should not be this difficult, twice now I have gotten an ‘upload failed’ error.

To save me tons of trial and error, when you publish yours, do you put them in a folder, or a model, or what? I am going to try to duplicate your workflow on this.

1 Like

Roblox is experiencing massive down problems now, that’s probably why, I’d wait until roblox.com is usable again.

I will look into this, I believe the solution is to save the plugin as a .rbxm instead of .lua in the same directory. You can do this by right clicking and selecting “Save to File…”

1 Like

lol, just my luck XD If it is not too much of an inconvenience, do you think you could try the 'right click on the plugin, and do ‘save as local’ to see if you get the same error?

1 Like

Didn’t even notice this, yeah, .lua files don’t save instances (in XML) so it should definitely be uploaded as a rbxm. It’s weird that they even give the lua option. (@SelDraken)