Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you change the background colour of a UI?

SOLVED - Check answers.

I am trying to create a darkening effect on a button when you press on it, similar to that of roblox's AutoButtonColor property. However, when I try to set the background colour (backgroundcolour3), it immediately changes to white, no matter the input in the parameters. Here's my localscript:

local buttons = script.Parent.Buttons
local research = script.Parent.ResearchUI

buttons.Frame.Research.MouseButton1Up:Connect(function()
	local debounce = false
	buttons.Frame.Research.BackgroundColor3 = Color3.new(232, 189, 136)
	if debounce then
		wait()
	else
		if research.Enabled == true then
			research.Enabled = false
		else
			research.Enabled = true
		end
	end
	debounce = true
	wait(0.1)
	buttons.Frame.Research.BackgroundColor3 = Color3.new(255, 208, 149)
end)

I don't get any errors in console, and everything seems to working completely fine. It happens on both the background color changes. Any suggestions?

8 comments

0

Hello, first mistake I see is .MouseButton1Up, instead of .MouseButton1Down, this shouldnt play a role but idk ;(

0

And try to use just .BackgroundColor, without that 3

0

MouseButton1Up works the same way as Down, except up only functions after you stop clicking, so if you're holding the click it won't click.

0

And I did try .BackgroundColor but that's only brick color so that doesn't work with the RGB values.

0

Yep, I know I just thought its a mistake because you wrote "when I press on it". Isnt line 18 the white color?

0

If it is, you got too low cooldown there

0

I commented everything inside the on mouse click function except for the first background color change and it still turns white when I click it, so it is something to do with line 6 and 18 on the actual change of color.

0

Huh?

1 answer

I solved it for anyone else who has this and needs to fix it. Since RGB values (Color3) are out of 255, when writing out a color3 value, / by 255. For example:

..BackgroundColor3 = Color3.new(255,152,111)

turns to:

..BackgroundColor3 = Color3.new(255/255,152/255,111/255)

Hope this helps anyone!

This discussion is preserved as it was. New answers, comments, and votes are closed.