I’m attempting to code a plugin, and I have a function that updates the plugin’s colors, first when you enable the plugin, and then if your theme changes.
Whenever I call “UpdateColors()” it errors. I’m not quite sure what’s going on since I do this exact same thing in my other plugin and it works just fine.
Any help would be much appreciated.
Code:
local MainUi = script.MainUi:Clone()
MainUi.Parent = Plugin
ToolbarButton.Click:Connect(function()
Plugin.Enabled = not Plugin.Enabled
if Plugin.Enabled then
UpdateColors() --It errors here
end
end)
settings().Studio.ThemeChanged:Connect(function()
UpdateColors() --And here
end)
function UpdateColors()
MainUi.BackgroundColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainBackground)
local Elements = MainUi:GetChildren()
for _, Element in pairs(Elements) do
Element:WaitForChild("Amount").TextColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.ButtonText)
Element:WaitForChild("Label").TextColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.ButtonText)
end
end
function UpdateColors()
MainUi.BackgroundColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainBackground)
local Elements = MainUi:GetChildren()
for _, Element in pairs(Elements) do
Element:WaitForChild("Amount").TextColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.ButtonText)
Element:WaitForChild("Label").TextColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.ButtonText)
end
end
This part is called defining the function, and it needs to be defined before you call it
I recommend reading PIL, it’s extremely informative!
local MainUi = script.MainUi:Clone()
MainUi.Parent = Plugin
function UpdateColors()
MainUi.BackgroundColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainBackground)
local Elements = MainUi:GetChildren()
for _, Element in pairs(Elements) do
Element:WaitForChild("Amount").TextColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.ButtonText)
Element:WaitForChild("Label").TextColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.ButtonText)
end
end
ToolbarButton.Click:Connect(function()
Plugin.Enabled = not Plugin.Enabled
if Plugin.Enabled then
UpdateColors() --It errors here
end
end)
settings().Studio.ThemeChanged:Connect(function()
UpdateColors() --And here
end)