Hello, I am currently making a custom gamemode to practice my lua skills. I’ve encountered an error when creating the HUD for my ammo. Could I have some help please?
Here is the error:
[ERROR] gamemodes/deathmatch/gamemode/cl_hud.lua:93: attempt to call method 'GetActiveWeapon' (a nil value)
1. unknown - gamemodes/deathmatch/gamemode/cl_hud.lua:93
2. include - [C]:-1
3. unknown - gamemodes/deathmatch/gamemode/cl_init.lua:2
Here is the relevant code:
if(client:GetActiveWeapon():IsValid()) then
if (client:GetActiveWeapon():GetPrintName() != nil) then
draw.SimpleText(client:GetActiveWeapon():GetPrintName(),"Trebuchet24",260,ScrH() - 60,Color(255,255,255), 0, 0)
end
if (client:GetActiveWeapon():Clip1() != -1) then
draw.SimpleText(client:GetActiveWeapon():Clip1().."/"..client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()),"Ammo", 260, ScrH() - 40,Color(255,255,255), 0,0)
else
draw.SimpleText(client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()),"Ammo",260,ScrH() - 40,Color(255,255,255),0,0)
end
end
Just in case its important, client has been declared as LocalPlayer().
Any help would be appreciated. Thank you.