Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you change the background colour of a UI?

Asked by
KingDomas 153
2 years ago
Edited 2 years ago

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?

0
Hello, first mistake I see is .MouseButton1Up, instead of .MouseButton1Down, this shouldnt play a role but idk ;( BeautifulAuraLover 371 — 2y
0
And try to use just .BackgroundColor, without that 3 BeautifulAuraLover 371 — 2y
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. KingDomas 153 — 2y
0
And I did try .BackgroundColor but that's only brick color so that doesn't work with the RGB values. KingDomas 153 — 2y
View all comments (4 more)
0
Yep, I know I just thought its a mistake because you wrote "when I press on it". Isnt line 18 the white color? BeautifulAuraLover 371 — 2y
0
If it is, you got too low cooldown there BeautifulAuraLover 371 — 2y
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. KingDomas 153 — 2y
0
Huh? BeautifulAuraLover 371 — 2y

1 answer

Log in to vote
0
Answered by
KingDomas 153
2 years ago
Edited 2 years ago

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!

Ad

Answer this question