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

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

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

✓ Accepted answer

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


2 comments

0

thanks for this!

0

Yeah, 2 things I forgot xD

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 :)

2 comments

0

this did not work for me unfortunately

0

" r cannot be assigned to" was what i got

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