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

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

Asked by
Prioxis 673 Moderation Voter
8 years ago

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?

1
try replacing 255 with 1, and 27/53 to 27/255 and 53/255. TheHospitalDev 1134 — 8y
0
ah okay thanks :) Prioxis 673 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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

Ad

Answer this question