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

Why does the BackgroundColor3 change when I set it to a specific value?

Asked by 4 years ago
Edited 4 years ago

I have a script that detects key presses within a Frame, because of the nature of the game the key input can be either right or wrong, so, therefore, I change the background color of the GUI element to let the user know if the answer he submitted (through keypresses) was correct or not. Then I set the GUI element attribute "Visible" to false and change the color back to the original [48,48,48] in readiness for the next GUI element, however, the next time that same GUI element appears, the color looks like [255,255,255] but observing the value shows me some ridiculously high numbers in the tens of thousands.

I'm not sure why it is happening, so here's my code:

local user_input = game:GetService("UserInputService")
local picked = false

user_input.InputBegan:Connect(function(key_input)
    if key_input.KeyCode == Enum.KeyCode.F and picked == false and script.Parent.Visible == true then
        picked = true
        script.Parent.BackgroundColor3 = Color3.new(0,225,0)
        wait(2)
        game.ReplicatedStorage.OptionPicked:FireServer(true)
        script.Parent.Visible = false
        script.Parent.BackgroundColor3 = Color3.new(48,48,48)
    elseif key_input.KeyCode == Enum.KeyCode.G and picked == false and script.Parent.Visible == true then
        picked = true
        script.Parent.BackgroundColor3 = Color3.new(255,0,0)
        wait(2)
        game.ReplicatedStorage.OptionPicked:FireServer(true)
        script.Parent.Visible = false
        script.Parent.BackgroundColor3 = Color3.new(48,48,48)
    end
end)

Here is the picture of the BackgroundColor3 value before and after:

Before key was pressed (Original color): https://gyazo.com/bc0902afe740f86cf562def153af12fb

During key was pressed (Appears as [0,255,0]): https://gyazo.com/aeb13a75c151faeb76798dc3aff66950

After key was pressed (Appears as [255,255,255]): https://gyazo.com/12230b9a03afa91aca9017d97b1840a9

2 answers

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
4 years ago

The values in Color3s are on a scale from 0 to 1. So by specifying colors using Color3.new() that have values at 255, they are 255 times over the limit. For some reason, this doesn't error and in some cases can have some interesting effects on the colors, but is definitely not what you're going for.

So what you will want to do is press ctrl+F, and search for "Color3.new(", case sensitive, and replace it with "Color3.fromRGB(". Because fromRGB normalizes the RGB values into a format that Color3s use.

Ad
Log in to vote
0
Answered by 4 years ago

Check this

script.Parent.BackgroundColor3 = Color3.fromRGB(255,255,255)

Answer this question