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

Colors won't tween into the color red?

Asked by 6 years ago

I have this health scripting colors, and when the health changes color, it will tween to white first, and then tween to the next color (yellow,red), the first tween works (green,white,yellow) but the second tween won't (yellow,white,red), it seems that any color won't tween to the red color, but when I try tweening the red color to other colors, it works. Is there any problem with it?

elseif health >= 21 and health <=40 then
    healthcolor.ImageColor3 = Color3.new(255,255,0)--Yellow
    textbox.Text = 2
elseif health >= 1 and health <=20 then
    local tween = TweenService:Create(healthcolor, tweeninfo, 
    {ImageColor3 = Color3.fromRGB(255,255,255)}) --Yellow tween to white
    tween:Play()
wait(0.5)--Script wait until tween stop
    local tween = TweenService:Create(healthcolor, tweeninfo, 
    {ImageColor3 = Color3.fromRGB(255,0,0)})--White tween to red
    tween:Play()
wait(0.5)--Script wait until tween stop
    healthcolor.ImageColor3 = Color3.new(255,0,0)
    textbox.Text = 1
    while true do
    textbox.TextColor3 = Color3.new(255,0,0)
    wait(0.5)
    textbox.TextColor3 = Color3.new(0,0,0)
    wait(0.5)
    end
0
Nevermind, just found out that it works, but not all the time. I don't know why. I'm just gonna disable the tween MArzalAlBuchariZ 33 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

Hello,

I see an Issue with your values of the colours. I'm not sure if it will fix your issue, but you can try at least.

Explanation

On the wiki, it states the following about color3.new(r,g,b)

Returns a Color3 with the given red, green, and blue values. The numbers can range from 0 to 1.

This basically is saying that all the values have to be between 0 and 1 for the RBG colour values. And in your script, for example Line 18:

healthcolor.ImageColor3 = Color3.new(255,255,0)--Yellow

it doesn't follow the 0 - 1 rule.

Solution To comply with this, all that has to be done is to divide your values by 255. 25/255 = 1, therefore the previous line of code I showcased should be :

healthcolor.ImageColor3 = Color3.new(1,1,0)--Yellow

. It's the same with ImageColor3.new(r,g,b)

However, when you are using

{ImageColor3 = Color3.fromRGB -- the values are raging from 0 - 255

Final Code

elseif health >= 21 and health <=40 then
    healthcolor.ImageColor3 = Color3.new(1,1,0)--Yellow
    textbox.Text = 2
elseif health >= 1 and health <=20 then
    local tween = TweenService:Create(healthcolor, tweeninfo, 
    {ImageColor3 = Color3.fromRGB(255,255,255)}) --Yellow tween to white
    tween:Play()
wait(0.5)--Script wait until tween stop
    local tween = TweenService:Create(healthcolor, tweeninfo, 
    {ImageColor3 = Color3.fromRGB(255,0,0)})--White tween to red
    tween:Play()
wait(0.5)--Script wait until tween stop
    healthcolor.ImageColor3 = Color3.new(1,0,0)
    textbox.Text = 1
    while true do
    textbox.TextColor3 = Color3.new(1,0,0)
    wait(0.5)
    textbox.TextColor3 = Color3.new(0,0,0)
    wait(0.5)
    end

I hope this helps.

That's the only problem I see. Can you also show the output?

0
The output doesn't show any errors, what's the difference with the script above? MArzalAlBuchariZ 33 — 6y
0
I cahnged it now. On Lines 2, 13, 16,18, all the numbers have been divided by 255 tonyv537 95 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Instead of using Color.new() use Color.fromRGB()

Answer this question