Plugin wont change color of UI text?

Hello, I am currently working on making a plugin and need it to save a few settings. I am using TextButton’s for this and change the color of the text depending on if they are on/off. The saving works fine, however when I try to set the color of the TextButton’s text again, the plugin just doesn’t change the text color. Instead the colors are set to what I have as the defaults which isn’t handled by the plugin (I just set those colors when designing the UI out of the script). What I find strange is that the script can change the color when I change a setting (by clicking on the text buttons) just not when I load the settings back in again after reloading the plugin.


I’ve tested to make sure that the load function is being invoked and it is. I have also made sure there is nothing else changing the color back to the defaults (even used a .Changed event and nothing changed at all). I have tried different methods of doing the same thing (such as moving the code to a module, instead of using my current method of loops, just setting it manually, and even using a while loop to repeatedly set the color to see if after a period of time, it would set). None of this worked. The data being saved is accurate as I opened the JSON file it is kept in and made sure the values matched what they should after saving.

I should also note there are no errors in the output.


Here is my code

local function updateSettings()
	local data = {
		["disableToggle"] = disableToggle,
		["autoToggle"] = autoToggle,
		["clearOnExitToggle"] = clearOnExitToggle,
		["deletingToggle"] = deletingToggle
	}
	
	plugin:SetSetting("Settings " .. game.GameId, data)
end

local function loadSettings()
	local data = plugin:GetSetting("Settings " .. game.GameId) or nil
	
	if data then	
        -- Set toggle/on off vars
		disableToggle = data.disableToggle
		autoToggle = data.autoToggle
		clearOnExitToggle = data.clearOnExitToggle
		deletingToggle = data.deletingToggle

		-- create dictionary of values
		local toggles = {
			[disableToggle] = disable.TextButton,
			[autoToggle] = auto.TextButton,
			[clearOnExitToggle] = clearExit.TextButton,
			[deletingToggle] = delete.TextButton
		}

		-- set colors
		for i, v in pairs(toggles) do
			if i then
				v.TextColor3 = Color3.fromRGB(62, 255, 52)
			else
				v.TextColor3 = Color3.fromRGB(255, 76, 76)
			end
		end
	end
end

The updateSettings() function is invoked when a settings is changed. The loadSettings() function is invoked as soon as the game id is valid.


Here’s how I change the color of a setting when you click on the button. For some reason the color change works here. Don’t know why.

Anyway here’s the code:

clearExit.TextButton.MouseButton1Click:Connect(function()
	clearOnExitToggle = not clearOnExitToggle

	if clearOnExitToggle then
		clearExit.TextButton.TextColor3 = Color3.fromRGB(62, 255, 52)
		updateSettings()
	else
		clearExit.TextButton.TextColor3 = Color3.fromRGB(255, 76, 76)
		updateSettings()
	end
end)

I have no idea why this is happening, but maybe it’s something really simple that I just haven’t seen. Any help is greatly appreciated!

Thank you.

For some reason I was able to fix this by not using the loop method (in a slightly different way than before). I don’t know why but the toggles dictionary wasn’t holding any values so it never looped through anything. Anyway it wasn’t from what I can tell anything plugin specific.