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

RGB color isn't changing on Frame, what is wrong?

Asked by 6 years ago

I want the RGB to change based on the textboxes which contain a number and it changed the color of the frame. It is not working.

while true do
    wait()
    script.Parent.BackgroundColor3.r = script.Parent.HMR.Text
    script.Parent.BackgroundColor3.b = script.Parent.HMB.Text
    script.Parent.BackgroundColor3.g = script.Parent.HMG.Text
end

If more info is needed, then please ask me in the comments.

2 answers

Log in to vote
1
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
6 years ago
Edited 6 years ago

Adding onto RedCommanders answer, you can only set a color3 with all values set at once, so not each individually.

The math.min and math.max makes sure that the value is between 0 and 255.

I've also added or 0 after the declaration of the variables, may the user input anything like "lol", it wont error because it now would see it as 0 instead of nil

while true do
    wait()
    local nR = math.max(0,math.min(255,tonumber(script.Parent.HMR.Text) or 0 )) 
    local nB = math.max(0,math.min(255,tonumber(script.Parent.HMB.Text) or 0 )) 
    local nG = math.max(0,math.min(255,tonumber(script.Parent.HMG.Text) or 0 )) 

    script.Parent.BackgroundColor3.r = Color3.fromRGB(nR,nB,nG)
end


0
thanks for this! AbstractDrawing 6 — 6y
0
Yeah, 2 things I forgot xD User#20388 0 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

What you type is a string, not a number.

Lucky for you it's easy to make it a number, just use tonumber()

while true do
    wait()
    local nR = tonumber(script.Parent.HMR.Text)
    local nB = tonumber(script.Parent.HMB.Text)
    local nG = tonumber(script.Parent.HMG.Text)

    if nR and nB and nG then
        script.Parent.BackgroundColor3.r = nR
        script.Parent.BackgroundColor3.b = nB
        script.Parent.BackgroundColor3.g = nG
    end
end

The if is to check if they are numbers

If you have a question, just ask :)

0
this did not work for me unfortunately AbstractDrawing 6 — 6y
0
" r cannot be assigned to" was what i got AbstractDrawing 6 — 6y

Answer this question