Custom Math Formula using RGB values

What do you want to achieve? Keep it simple and clear!?

Simple Request: I want to find a formula where when a certain number decreases, the percentage would increase.

Here is my code where I would implement this formula

WeaponsSystemGui.Ammo.primary.ignore.border.BorderColor3 = Color3.fromRGB(--[[Formula Here]], (CURRENT_BULLET / AMMO_CAPACITY) * 255, (CURRENT_BULLET / AMMO_CAPACITY) * 255)

Currently, if the CURRENT_BULLET increases, the amount of the color teal will increase. Now I want a formula that will increase the amount of red while the CURRENT_BULLET decreases. I have tried moving the formula around a bit but I still could not find what path I could do to create the solution.

The formula for teal: (CURRENT_BULLET / AMMO_CAPACITY) * 255

CURRENT_BULLET is how many shots are left in a gun
AMMO_CAPACITY is how many shots a gun can store
255 is the max value in the RGB table.

The formula has to:

  • satisfy for the formula of teal
  • share the value of CURRENT_BULLET and AMMO_CAPACITY from the first formula
  • the variable cannot have their own separate values

You could just use Color3.new(). Its basically RGB but the max value is 1, so therefore you can put the lower number on the numerator.

1 Like

OH! Thanks for the tip, I never thought Color3.new() would just take the scale of the values. Because of that, I was able to look at the formula easily. Your tip didn’t exactly find the solution, but I manage to find the formula which is:

(AMMO_CAPACITY - CURRENT_BULLET) / AMMO_CAPACITY

I wasn’t really trying to give you the exact solution, but i’m glad it works!

1 Like
((AMMO_CAPACITY - CURRENT_BULLET) / AMMO_CAPACITY) * 255

I know this is resolved but this is all you would have needed to add.

You’d essentially be getting a ratio between the amount of ammo fired & the ammo capacity (which would be represent a percentage between 0%-100% as a decimal value, then you’d multiply this decimal value by 255 before plugging it in the “Color3.fromRGB” constructor function.

1 Like