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

Trying to use a For Loop to slowly darken a color, Its very simple?

Asked by 6 years ago
Edited 6 years ago

I have a gun script and I have been modifying the heck out of it over the past couple of days, but out of all the things I cant figure out. It has to be this simple thing XD

I am trying to have it so the lower your ammo count the closer the color is to red.

Heres the code I have at the moment. I am 100% sure I am just having a brain fart and I cannot figure it out, but maybe one of you guys can.

for i = Ammo, 5 do
    GUI.Frame.Ammo.Fill.BackgroundColor3 = Color3.new(5,5,5)
end

Thank you for your time my dudes, and Merry Christmas!

1 answer

Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
6 years ago
Edited by RubenKan 6 years ago

Lets say by default, the rgb color would be 5,5 5. If you wanted it to be closer to red based on the ammo count, you could say if we had 10 bullets out of 100, the r property of color3 needs to be 30, (5 + 25). 25 since 10/100 of 250 is 25. So for every bullet not there, the r property should be increased by 2.5. So, color3.fromRGB(5 + ((ammo / totalAmmo) * 2.5), 5, 5).

EDIT:

while wait(0.5) do
    Color = Color3.fromRGB(5 + ((ammo / totalAmmo) * 2.5), 5, 5)
end

TLDR;

Simply increase the red property of color3. Each bullet not accounted for should be 1 / totalAmmo of (255 - default property) which is the color for max ammo. In this case 250. For every bullet shot, increase the color by 2.5

Edit by RubenKan

Changed Color3.new in your codeblock to Color3.fromRGB

Ad

Answer this question