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

Why does this text box not actually match up with a Color3Value's value?

Asked by 6 years ago
Edited 6 years ago

So, if anyone used Microsoft Paint and click Edit Colors, theres a menu to create any color you want. So, I'm trying to recreate that. I tried making a text box to display the current RGB value and HSL value. Here is what I decided

local color = script.Parent.Parent.Parent.CurrentColor
local r, g, b = color.Value.r * 255, color.Value.g * 255, color.Value.b * 255
script.Parent.R.TextBox.Text = r
script.Parent.G.TextBox.Text = g
script.Parent.B.TextBox.Text = b
wait()
color.Changed:Connect(function()
    local f = math.floor
    local r, g, b = color.Value.r * 255, color.Value.g * 255, color.Value.b * 255
    script.Parent.R.TextBox.Text = f(r)
    script.Parent.G.TextBox.Text = f(g)
    script.Parent.B.TextBox.Text = f(b)
end)

local inputs = {
    script.Parent.R.TextBox;
    script.Parent.G.TextBox;
    script.Parent.B.TextBox
}

wait(.1)
for _, inputs in pairs(inputs) do
    local prev = inputs.Text
    local deb = false
    inputs.Changed:Connect(function()
        if not deb then
            deb = true
            local txt = require(script.Parent.Parent.Parent.NumConstrain):Constrain(prev, inputs.Text)
            if txt then
                if tonumber(txt) then
                    inputs.Text = math.floor(string.sub(txt, 1, 3))
                end
                local n = tonumber
                local r, g, b = n(script.Parent.R.TextBox.Text) or 0, n(script.Parent.G.TextBox.Text) or 0, n(script.Parent.B.TextBox.Text) or 0
                color.Value = Color3.fromRGB(r, g, b)
            else
                inputs.Text = txt
            end
            wait()
            deb = false
        end
    end)
end

You don't need to worry about the requiring though, it is just to keep the text in the textbox a number from 0 to 255 with no letters.

However, when I click play, I go into the explorer and get my CurrentColor value. I change it to 0, 0, 0 in the little pop up when you edit colors, and the properties in the CurrentColor value say 2, 2, 0 and my display says 2, 2, 2. Also, my HSL display for the color is wrong too with 120, 255, 255 in the popup and 85, 255, 255 in the display. Is this a roblox bug, or what did I do terribly wrong with my code?

0
If you didn't know, I convert RGB to HSL using Color3.toHSL hiimgoodpack 2009 — 6y
0
I just tested your script and it appears to be working correctly (though I replaced line 28 with "local txt = tonumber(inputs.Text)". I assume you mean "HSV", btw; your script doesn't mention "HSV" (or HSL) anywhere. I recommend using 'print' to debug what is and isn't going on. chess123mate 5873 — 6y
0
Oh, okay got the wrong values on the side that is supposed to show HSV. hiimgoodpack 2009 — 6y

Answer this question