Comparing BackgroundColor3 to Color3 not working

I’m trying to find whether any of the other buttons have been selected by looping through all the buttons to see if they’re a darker color than the normal color.

local function checkForSelection(Frame)
	local found
	
	for _, Button in pairs(Frame:GetChildren()) do
		if Button:IsA("TextButton") then
			if Button.BackgroundColor3 == Color3.new(0.129412, 0.129412, 0.129412) then
				print(Button.Text)
				found = Button
			end
		end
	end
	
	return found
end

But my code never makes it past the if statement comparing BackgroundColor3 to Color3. I’ve printed what BackgroundColor3 is and it is the exact same as the Color3 value but for some reason the code doesn’t advance.

Try using Color3.fromRGB instead of Color3.new.

Have you tried using Color3.fromRGB?

Yeah, I’ve tried this before and it still doesn’t work.

When are you calling the checkForSelection() function?

local function burgerSelection()
	if #string.split(MainFrame.Slot1.Text, "") == 0 or #string.split(MainFrame.Slot2.Text, "") == 0 or #string.split(MainFrame.Slot3.Text, "") == 0 then
		if checkForSelection(MainFrame.FirstSelection) then
			
		end
	else
		SendNotification:FireServer("No available slots", "Red")
	end
end

Is a localscript changing the background color of the button, or is it the Roblox core scripts changing it when you hover your mouse over it?

I haven’t gotten to that part yet, my biggest priority is to make sure it can identify if it’s that certain color so as of now I’ve manually set the color of one button to that certain color.

Are you calling the burgerSelection() function when you click on the “selection” button?
A little confused here.

Actually, I was messing around with my script and found my problem.

if Button.BackgroundColor3 == Color3.fromRGB(33, 33, 33) then
	print(Button.Text)
	found = Button
end

I wasn’t changing the color value after making it fromRGB.

1 Like

That’s great, good luck on scripting your system. Happy holidays!

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