Dynamic Plugin Icon

Greetings, in this tutorial we’re going to make the plugin icon change according to Studio theme. So let’s start!

For what purpose?
Simply, only If you opt for a single-color icon, such as black or white, it ensures compatibility across various themes. This consideration is especially important as not all users prefer the Light theme.

If we don’t create a dynamic icon, the result will look like this:

imagen_2023-11-28_200040331

Before start :white_flag:
You need at least two icons that contrast with light and dark themes. For example:

9087232887_dark This is for Light theme

9087232887_light This is for Dark theme

Once it’s done, let’s continue!

Creating the button on Toolbar
So first, let’s create the plugin button. To do this, just create a new script (you can paste it anywhere). After that, you must type this:

local Toolbar = plugin:CreateToolbar("Plugin section name")

With this, we’ve created the plugin on the Toolbar. You can change ‘Plugin section name’ to whatever you want.

Okay, now let’s make the buttons.

local PluginButton = Toolbar:CreateButton(
"Click me!", -- Button name (this will appear below button)
"This is just a description ", -- Text that appears when you hover your mouse on button
"rbxassetid://15491708985") -- Button icon

Note: button image must be Image ID, not Decal ID

We’re done with the button! To verify if everything is correct, you must save your plugin.
image
(Image by @alexsany, found on How to create your own plugin)

2. Scripting the button
Now let’s script the functionallity of the button, since this tutorial is enfocated to do a dynamic icon, we’re going to script that.

To get Studio available themes, you need to type this:

-- Gets Studio themes
local studioThemes = settings().Studio:GetAvailableThemes()

Next, we create a function that updates the icon depending on Studio theme:

local function updateIcon()
	if settings().Studio.Theme == studioThemes[1] then -- Light Theme
		PluginButton.Icon = "rbxassetid://15491708985" -- Light Theme Icon
	elseif settings().Studio.Theme == studioThemes[2] then -- Dark Theme
		PluginButton.Icon = "rbxassetid://9087232887" -- Dark Theme Icon
	end
end

Next, we script a function that detects theme changes:

-- Fires when studio theme is changed
settings().Studio.ThemeChanged:Connect(function()
	updateIcon() -- calls function to update icon
end)

And finally, we call the function again to apply changes:

--
updateIcon() -- calls function to update icon

Once it’s done, you must save the plugin again to test it out, and then it should work like this:
ezgif.com-video-to-gif

3. The end
That’s it! you created your own dynamic icon!

That’s all for this tutorial, If you come across any mistakes or find something unclear, please don’t hesitate to ask!

:warning: Known issue: In play mode and after play mode, the icon gets replaced by text. I couldn’t find a way to fix that sorry

:heavy_check_mark: This doesn’t affect plugin functionality, as it’s merely an aesthetic issue, so don’t worry.
:thought_balloon: The easy solution for this is to simply save the plugin again (if you are creating your plugin) or disable and enable it (if you uploaded your plugin to the marketplace).

10 Likes

I feel like this would be pretty cool to also implement with the plugin’s GUI elements too. You can automatically make the plugin based on the players preference.

7 Likes