Text Fading


I’m really confused as to how to make my text fade. As in:

I want a name to fade from being (alpha 255) to (alpha 0) and back again.

Please help.

Something like this maybe? If you want it to look cool (and use less code), use Sin() to increment and decrement your numbers.

local slowingthing; = 10;               //I really don't know how slow to make this...
local iterator;     = 0;
local color         = 0;                //Starting number
local increment     = true;             //should the color number increase or decrease?
hook.Add("Hudpaint", "What is ths point of naming these...?", function()
        iterator = iterator + 1;        //Yes, I know you can use ++  
                                        //This little block of code here will slow down the hudpaint hook
    if (iterator >= slowingthing) then  //by checking to see if the var incremented to your number
        iterator = 0;
        if (increment == true) then     //Check to see if we should add to color or subtract from it.
            color = color + 1;
        elseif (increment == false)
            color = color - 1;  
        if (color >= 255) then          //If the color is at 255, then make the code decrement next cycle.
            increment = false;
        elseif (color <= 0) then 
            increment = true;


        Add your hudpaint drawing stuff here.


That should work as posted, but then again, I haven’t wrote Lua in months.

Or math.sin(CurTime() * speed) * 255

All I can really say to that is it’s not painting the HUD, it’s Setting the text of a row on a Scoreboard to something that I want to fade (hence the alpha)

text.Think = function(text)
text:SetTextColor( Color(math.sin(CurTime() * 2) * 255, 255, 255) )