Blood Spat on screen when shot [TTT]

Hello, how would I go about making blood spill on your screen when you get shot/damaged in-game?
I went back through a couple threads, someone had the same question as I did, but not for Trouble in Terrorist Town.
The code is from Zombie Onslaught:
function GM:HUDPaint()



function GM:OnHUDPaint()

function GM:PaintBlood()

if #Stains < 1 then return end
for k,v in pairs( Stains ) do
    v.Alpha = math.Approach( v.Alpha, 0, FrameTime() * v.DieRate * -1 )

    surface.SetTexture( v.Mat )
    surface.SetDrawColor( 255, 10, 10, v.Alpha )
    surface.DrawTexturedRectRotated( v.X, v.Y, v.W, v.H, v.Rotation )
for k,v in pairs( Stains ) do
    if v.Alpha < 2 then
        table.remove( Stains, k )

    elseif not LocalPlayer():Alive() then
        v.DieRate = 30


function AddStain()
local x, y, w, h = ScrW() * math.Rand(-0.2,1), ScrH() * math.Rand(-0.2,1), ScrW() * math.Rand(0.3,0.6), ScrH() * math.Rand(0.3,0.6)
table.insert( Stains, {X = x, Y = y, W = w, H = h, Mat = table.Random( StainMats ), DieRate = math.Rand(5,15), Rot = math.random(0,360), Alpha = math.random(50,150)} )
I added this to my “cl_hud.lua” but only resulted in the error

ERROR: GAMEMODE:'HUDPaint' Failed: [terrortown\gamemode\cl_hud.lua:362] attempt to get length of global 'Stains' (a nil value)

The similar thread is at

My guess is that the Lua is asking for the length of the table ‘Stains’ but it doesn’t exist, according to the code you gave us.

Try adding stains = {} at the top of your script.

What’s the point of making a function OnHUDPaint that just calls PaintBlood when you can just call PaintBlood directly?

Stains since it’s case sensitive.