How do you reference an already existing plugin toolbar?

I’m creating a plugin and when updating it instead of getting an error message trying to create another toolbar I want to just use the already existing toolbar.

The issue is that I do not know of any way to reference it using plugin.

I’ve tried to look on the developer hub but I couldn’t find anything. I’ve also looked on the forums but haven’t found anything.

Any help would be appreciated.

3 Likes

Haven’t tested it but you could always try storing a reference to the toolbar in _G if you plan on having your plugins share a toolbar. Maybe pop in a feature request to allow plugins to share a toolbar if they have the same name as an optional argument of CreateToolbar.

1 Like

Good idea. I’ll try it. I’ll also create that feature request aswell. Sounds like it could be very useful in the future.

You will have to play around with it. I don’t know how Studio handles toolbars when unloading plugins (e.g. when you update/uninstall/install a plugin). You might find that the toolbar is disposed during this process, but the reference will still be valid.

On a side note I’m sure the previous version of Studio (1.0) used to allow plugins to share a toolbar if they had the same name, rather than creating a new toolbar.

By the standard practice this cannot be done (to my knowledge), but there is a way to do it.

Whenever a plugin Toolbar is made, it creates a Toolbar Instance, and like any other Instance (aside from services) you can set its parent (by default the parent is nil and thus never seen). You can just set the parent to game and it won’t be seen by anyone (unless they have a specific setting turned on in Studio that reveals hidden objects). You’ll also have to set the Name property since the name displayed on top isn’t the same as what it actually is. See the image below:


I personally like to use this for my plugins to replicate the old behavior of multiple plugin buttons attaching to the same Toolbar from multiple plugins.

So when you’re trying to find the Toolbar, you can now make a check for if it already exists. I’d recommend that you’d simply make a check for the toolbar, delete it, and then make the new one. If you try reusing the toolbar, you’ll get the error that warns you about trying to make the same button in the toolbar, and that comes with its own solution, but that’s just more unnecessary work.

2 Likes

Dang. It didn’t work. I’ll make a feature request for it tho. Thanks for the help.

1 Like

I don’t see that in my advanced objects. The toolbar name is Interface.

PluginToolbars can only be created by CreatePluginToolbar, you aren’t meant to insert it from the Advanced Objects menu. When you use the function, parent the PluginToolbar instance returned from the method to game to replicate that behaviour.

I wasn’t talking about that I was talking about the all the extra services you can enable in settings. Sorry for any confusion.

…?

image

? This thing? You wanted to see all those hidden objects?

1 Like

Yes I forgot the name of it. I’m currently trying to use your method and so far its going well.

This is what I currently have

https://gyazo.com/a4bda3cedd7449d6cc6d74d085e3c97b

And this is the error I have:

https://gyazo.com/dfc4a877599233bd2012cb9e49dc333a

Could you post those images as uploads or as text instead of Gyazo links? I hate opening Gyazo links and it’s better to actually have your items in the thread since it’s more accessible (e.g. if I need to copy/paste parts of the code or see it better).

By the way…

1 Like

My geometry tools (GapFill, ResizeAlign, etc…) put all of their buttons in the same toolbar even though they’re separate plugins. You can copy paste the code I use to do that if you want an easy solution. (All of those plugins are single-script plugins that I coded before ModuleScripts were added, so you won’t have to dig much to find the relevant code)

8 Likes

What GUI? Like, did you copy the whole draggable settings GUI from my plugin? I don’t remember the code well enough to have a guess what you did wrong in that case.

I have a script that inserts my GUI into the core scripts. It just clones it in there if it doesn’t already exist. When I play the game, it still does this even tho it’s a plugin script. And no, I just looked at the code and kind of wrote my own version of it.

1 Like

(the code is this, for future people - just replace the toolbar’s prefix)

local toolbar;
local toolbarCombiner = game:GetService("CoreGui"):FindFirstChild("CUSTOMNAMEToolsToolbar")
if toolbarCombiner then
    toolbar = toolbarCombiner.Value
else
    toolbar = plugin:CreateToolbar("CUSTOMNAMETools")
    toolbarCombiner = Instance.new("ObjectValue")
    toolbarCombiner.Value = toolbar
    toolbarCombiner.Name = "CUSTOMNAMEToolsToolbar"
    toolbarCombiner.Parent = game:GetService("CoreGui")
end
18 Likes