One way to handle close numbers is to introduce a buffer zone or threshold value to determine when to switch from one color to another. For example, if your buffer zone is set to 5, then any value between 95 and 105 would be the same color, while values below 95 would be yellow and values above 105 would be red.
Here’s an updated script that incorporates a buffer zone:
local Yellow = Color3.fromHSV(0.1344, 0.9328, 0.9333)
local Red = Color3.fromHSV(0.0155, 1, 0.9294)
local BufferZone = 5
if Value <= MaxValue - BufferZone and Value >= BufferZone then
local MidColor = Yellow:lerp(Red, 0.5)
local LerpValue = (Value - (MaxValue - BufferZone)) / (BufferZone * 2)
ValueFrame.BackgroundColor3 = Yellow:lerp(MidColor, LerpValue)
elseif Value < BufferZone then
ValueFrame.BackgroundColor3 = Yellow
else
ValueFrame.BackgroundColor3 = Red
end
If the value is less than the buffer zone, we set the color to yellow. If it’s greater than the buffer zone, we set the color to red.