DarkRP - HUD PlayerName Changes font help?

Hi, bassically i’m trying to make players usernames fit on my hud by changing the font to a smaller font if their name is over 20 characters. This is what i have so far but it isn’t working. Could somebody fix please and tell me why it isn’t working. Thanks in advance.



surface.CreateFont( "name", {
 font = "Trebuchet24",
 size = 48,
 weight = 500,
 blursize = 0,
 scanlines = 0,
 antialias = true
} )

local PlayerName = LocalPlayer():Nick()
		local PlayerNameSize = surface.GetTextSize(PlayerName)
		if PlayerNameSize > 20 then
		font = "Trebuchet24"
		draw.DrawText( " "..PlayerName, font, 0 + 10, ScrH() - 75, Color(255, 255, 255, 255))
	else 
		font = "name"
    end


you have to set a font for surface.GetTextSize to work correctly, but if you’re only looking for character width, then you don’t have to use surface.GetTextSize at all



local PlayerName = LocalPlayer():Nick()
local font = "Trebuchet24"

if #PlayerName > 20 then
	font = "name"
end

draw.DrawText(PlayerName, font, 0 + 10, ScrH() - 75, Color(255, 255, 255, 255))


Didn’t you ask basicly the same question here and someone showed you how to do it.