• Error with Ammo HUD
    4 replies, posted
Currently trying to make the "Clip1" part of my gamemode's HUD. Here's my code: [CODE] if (ply:GetActiveWeapon():Clip1() != -1) then draw.SimpleText(LocalPlayer():GetActiveWeapon():Clip1(), "DermaLarge", 1300 + 30,ScrH() - 63, Color(255,255,255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP ) else return false end[/CODE] Here's my error (Occurs upon death): [CODE][ERROR] gamemodes/rogue/gamemode/cl_init.lua:78: attempt to call method 'Clip1' (a nil value) 1. v - gamemodes/rogue/gamemode/cl_init.lua:78 2. unknown - lua/includes/modules/hook.lua:84 [/CODE] Any help is appreciated.
Are you sure that function is running clientside and not serverside as well?
All the code here is clientside. Nothing about 'Clip1' on serverside.
Wait, I just noticed, you seem to use 'ply' when checking the clip isn't -1, but then you use LocalPlayer() later. Have you defined ply?
"ply" has been defined. I just tried changing it to: [CODE] if (LocalPlayer():GetActiveWeapon():Clip1() != -1) then draw.SimpleText(LocalPlayer():GetActiveWeapon():Clip1(), "DermaLarge", 1300 + 30,ScrH() - 63, Color(255,255,255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP ) else return false end[/CODE] But the error occurs still. [editline]28th August 2016[/editline] I managed to fix it by doing this: [CODE] if LocalPlayer():GetActiveWeapon():IsValid() then draw.SimpleText(LocalPlayer():GetActiveWeapon():Clip1(), "DermaLarge", 1300 + 30,ScrH() - 63, Color(255,255,255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP ) else return false end[/CODE]
Sorry, you need to Log In to post a reply to this thread.