How can I make something slowly change color depending on a value?

So to explain what I am trying to do.
In my game if you get shot you will leak blood from a bullet wound. You will be able to apply bandages to slow the bleeding. Eventually the bandage will soak up too much blood and you will have to apply another.

I want to make the bandage slowly turn from the color white to red as the players blood goes down. How should I go about doing this?

3 Likes

It depends whether blood level is some value or the bandage heals fully over some period of time.

For example this would change the color of it in 5 seconds:
game:GetService("TweenService"):Create(bandagePart,TweenInfo.new(5),{Color = Color3.fromRGB(255,0,0)}):Play()

If “blood level” is a IntValue, you could tween that and connect function to it being changed. If it is a local variable in a script you’d have to change the color whenever you change the value by something like bandagePart.Color = Color3.new(currentBlood/maxBlood,0,0) where currentBlood is slowly going down as the player is getting healthier i guess

3 Likes

The tween wont work as the time it takes to shift to red will always vary.
I guess a good way to go about this would be finding a way to add a percentage of red to white.

e.g how could I add 10% or 50% of red to the color white?

You would have to run a :Lerp on .RenderStepped.

local white = Color3.new(1, 1, 1)
local red = Color3.new(1)

-- 10%
print(white:Lerp(red, 0.1))

-- 50%
print(white:Lerp(red, 0.5))
2 Likes

If you mean that the whole healing period could vary then you can just change the time the tween takes to complete in the TweenInfo.new(time) (if you generate the time beforehand ofc)

If you want to add just chunks at a time (like 10%) then the above suggestion should do fine (had no idea colors have lerp function xd)

1 Like

I believe I found a simple solution
Simply get color from RGB and change the green and blue values.

Color3.fromRGB(255,255,255)

The more I lower the green and blue values the more red it gets.
So I just take the % of health the bandage has left and make the green and blue values and make them that % out of 255.