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

Why does changing a UI elements background color using color3 make it all weird?

so for some reason when I change a button's background color with

this script

local player = game.Players.LocalPlayer
local button = script.Parent

script.Parent.MouseEnter:connect(function(over)
	button.Size = UDim2.new(0, 210, 0, 50)
	button.BackgroundColor3 = Color3.new(0, 255, 0)
	button.Position = UDim2.new(0, 15, 0.6, 0)
end)

script.Parent.MouseLeave:connect(function(over)
	button.Size = UDim2.new(0, 200, 0, 50)
	button.Position = UDim2.new(0, 0, 0.6, 0)
	button.BackgroundColor3 = Color3.new(27, 42, 53)
end)

after my mouse leave event fires the button is white and has a color3 value of

6885, 10710, 13515 what causes this and how do I fix it?

2 comments

1

try replacing 255 with 1, and 27/53 to 27/255 and 53/255.

0

ah okay thanks :)

1 answer

✓ Accepted answer

Color3 is a [0-1] float

The whole idea of colours being out of 255 is wrong. It's a convenience made by the ability to represent it easily in the form of 8 bytes. In terms of colour theory, it's a terrible representation, and therefore most engines benefit from internally representing it as a float or double. As a result, you'll need to make all your values range from 0 to 1

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