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

Why is my script instantly making the frame white?

So, I've gotten better at scripting. I am working on a myth game, And want to make the screen fade out. I use a screengui (Duh) and a frame in that screengui. In the frame is this script:

waitt = 1
------------------------------------
wait(5)
r,g,b = 0,0,0
for v = 1, 255 do
wait(waitt)
r,g,b = r+1,g+1,b+1
script.Parent.BackgroundColor3 = Color3.new(r,g,b)
print(r,g,b)
end

And its purpose is to make the BackgroundColor3 values + 1. If you do not know what i mean here is what i mean: Basically, Its making the r,g, and b variables + 1. Then, we do:script.Parent (<--Frame).BackgroundColor3 = Color3.new(r,g,b) Why? Wel, I noticed when something completely is black the numbers are 0,0,0. When i change it to like 100,100,100 it will become more white. BUT, i did this and my script makes the frame instantly white. I do not know why, That is why i am asking it. I hope you find a answer to this question.

2 answers

Color3.new() strictly takes a floating point number between 0 and 1. Anything above 1 will become 1.

In order to have it work, you have two options:

  • Use Color3.fromRGB(), which takes either an integer or floating point number between 0 and 255:
script.Parent.BackgroundColor3 = Color3.fromRGB(r,g,b)
  • Divide each number by 255. This is likely the best way to get accurate colors without using fromRGB:
script.Parent.BackgroundColor3 = Color3.new(r/255,g/255,b/255)

Using Color3.new() is quite funky when you're doing stuff like this. If you want integers, use Color3.fromRGB(). If you're OK with dividing the numbers, stick with the Color3.new() constructor.

2 comments

0

Hm. I didn't even know that fromRBG existed.

0

Very good explanation. Upvoted!

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