I’m trying to find an existing plugin toolbar button, because whenever I update my plugin it says that it cannot create a new toolbar button.
Is it possible to find an existing toolbar button for the plugin, or would I have to somehow delete the old one and replace it with a new one?
local ToolBar = plugin:CreateToolbar("Confix")
local FindButton = ToolBar:CreateButton("Find", "Search for Confix Products!","rbxassetid://4240253703")
The code above is what I’m current using, which does work unless I update the plugin, which it then throws out an error. I couldn’t find anything on the developer page about finding existing plugin toolbars and removing existing buttons.
The error being produced is:
[This toolbar cannot create more than one button with id: “cloud_4485223525_Confix_Find”]
I believe this is an issue in regards to how plugins do not remove old toolbars when they’re updated due to the new plugin management workflow. You aren’t able to remove the toolbar yourself. Try deactivating and then updating your plugin.
Actually, this is possible in a way, but it’s an unofficial [color=red]hacky[/color] method that I don’t really recommend trying (as it might cease to work in the future). But it will get you your desired result too.
When you create a ToolBar it will create an Instance that’s just hidden from you. Once it’s created you can set it’s Parent to something. I’d just set it to game so most people won’t be able to see it (unless they turn on Hidden Objects in Studio’s Settings). You can also set a name for the ToolBar like how you’d do any other Instance.Name and in this case it can differ from what text will be displayed. You could also do the same when you create the Button (parenting it under the ToolBar and Naming its Instance).
So if you decide to do that, you can now have a check to see if the ToolBar and Button already exist and can be reused (assuming they’re not deleted) and it could look a bit like this:
--Making the ToolBar and Button variables:
local ToolBar,Button = game:FindFirstChild("ExampleName") or plugin:CreateToolbar("Confix"),nil
--Checking if the ToolBar already exists and was parented:
if not ToolBar.Parent==game then
--If it wasn't already made, set its parent:
ToolBar.Parent = game
ToolBar.Name = "ExampleName"
--Create the button:
Button = ToolBar:CreateButton("Find", "Search for Confix Products!","rbxassetid://4240253703")
Button.Parent = ToolBar
Button.Name = "ExampleName2"
else
--If it was already made, find the Button:
Button = ToolBar:FindFirstChild("ExampleName2")
if not Button then
--If there was no button:
Button = ToolBar:CreateButton("Find", "Search for Confix Products!","rbxassetid://4240253703")
Button.Parent = ToolBar
Button.Name = "ExampleName2"
end
end
Although if you don’t wish to reuse the old ToolBar and Button you can simply add a check for the ToolBar and delete it before making the new one. If you’re clever enough, you can take advantage of being able to find them and use this across multiple plugins if you wanted.
But as I said at the start, this is an [color=red]unofficial hacky method[/color] and it may cease to work in the future, so don’t get too comfortable with it. But for now, it will get your desired results.