How to get the color of a Button?

Hello, I’m trying to compare the color of a button to see if its a specific color. For example here is my script:

for i,v in pairs(game:GetDescendants()) do 
   if v:IsA("TextButton")  and v.BackgroundColor3 == Color3.new(0.631373, 0.258824, 0.258824) then 
      -- do stuff here
   end 
end

this doesnt work however because I cant compare

v.BackgroundColor3 == Color3.new(0.631373, 0.258824, 0.258824)

How do I do this

Use fromRGB

for i,v in pairs(game:GetDescendants()) do 
	if v:IsA("TextButton")  and v.BackgroundColor3 == Color3.fromRGB(0.631373, 0.258824, 0.258824) then 
		-- do stuff here
		print("Yo")
	end 
end

Now I feel that using directly color3.new instead of rgb is a bit unreliable since it can cause precision problems such as float points of comparing if its 0.4 but in reality color3 is 0.4546547457, you get the point, use what @RafehPvP said use from RGB.

1 Like

Wait I just noticed why are you going through all descendants of the game… Put all your Gui in StarterGui and whenever you need to do something, do it in a local script inside Player.PlayerGui.

The reason I did the game is because I am too lazy to write out starterGui. I know how to develop games.

the code that is shown is ran via the command bar so I dont have to manually recolor all the buttons

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.