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

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

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

✓ Accepted answer

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

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