I want to have a math formula that changes the color of a textlabel depending on a number which maxes at 100.
I want it so if the number is low enough, the color will be yellow-orange, if the number is around 50, then red, and if around 100 then its going to be around purple
Anyone know a formula or if this is even possible because theres 3 colors? If this isnt possible its ok ill just make a bunch of if-then statements
I don’t think there is a formula for that…
But you can still use if-else statements to achieve the same exact thing. It’s easy enough.
And btw, you don’t need to use a bunch of statements. Just use those >,<,= signs to simplify your code
for example:
if temp >= 0 and temp <= 50 then
textlabel.BackgroundColor3 = (whatever you want)
end
Sorry if I somehow messed up the code . My brain isn’t working today lol.
Well anyway, you get the idea
aight i see ig ill do that with if-elseif statements
According to me, you might just need 3-4 if-else statements. Check my previous reply (edited) if you are confused. Happy to help if you needed it!
Now that I think of it, I might have misunderstood your query…
if value >= 0 and value < 50 then
label.Color = FirstColor:Lerp(SecondColor,(value)/50)
elseif value >= 50 then
label.Color = FirstColor:Lerp(SecondColor,(value+50)/50)
end
You can use LinearInterpolation for that.
took me a little bit, but the “formula” that does this is
h = (-0.00002x^2 - 0.002x + 1.15) % 1
(where h is hue and x is your number 0-100)
then you can use Color3.fromHSV to get the actual color
local function getColor(number)
local h = (-0.00002 * number^2 - 0.002 * number + 1.15) % 1
return Color3.fromHSV(h, 1, 1)
end
local block = script.Parent
block.Color = getColor(100)
goot you got the same thing, good job! That kind of math isn’t easy. Took me 20+ tries. So, I’m still going to post it.
yoooo guys thanks
sadly i cant try it rn but i will try it possibly tomorrow
cant thank enough for how you guys got this since i think its not easy so yeah
yep it worked! thanks, I might tweak with the numbers a bit in the future
Rip it up, it’s yours now. Was fun working with quadratic regression again. Plus goot showed me a new toy, so I’m more than happy.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.