GetPrintName() error for hud help

This is the error i get when i change teams



[ERROR] addons/prop hunt/gamemodes/fretta/gamemode/cl_hud.lua:182: attempt to call method 'GetPrintName' (a nil value)
  1. OnHUDPaint - addons/prop hunt/gamemodes/fretta/gamemode/cl_hud.lua:182
   2. HUDPaint - addons/prop hunt/gamemodes/fretta/gamemode/cl_hud.lua:256
    3. unknown - addons/prop hunt/gamemodes/fretta/gamemode/cl_hud.lua:254


This is the code I’m using




if ply:Team() == TEAM_HUNTERS && ply:Alive() then
	if (ply:GetActiveWeapon():GetPrintName() != nil) then
		draw.DrawText(ply:GetActiveWeapon():GetPrintName(), "shudfont69", ScrW()/1.29, ScrH()/1.16, Color(255,255,255,255))
	end
end



Try this:


if ply:Alive() && ply:Team() == TEAM_HUNTERS then
	local wep = ply:GetActiveWeapon()
	if ( IsValid( wep )) then
		draw.DrawText(wep.GetPrintName and wep:GetPrintName() or wep:GetClass(), "shudfont69", ScrW()/1.29, ScrH()/1.16, Color(255,255,255,255))
	end
end

damn i didnt think of making sure it checked if it was a valid weapon thanks!