• Need help with HUD error!
    3 replies, posted
So i am currently working on my Gamemode and i codded a basic HUD, and every time i die, this error [ERROR] gamemodes/*gamemode*/gamemode/cl_init.lua:56: attempt to call method 'Clip1' (a nil value) 1. unknown - gamemodes/*gamemode*/gamemode/cl_init.lua:56 [CODE]function GM:HUDPaint() self.BaseClass:HUDPaint() local ply = LocalPlayer() local HP = LocalPlayer():Health() local ARM = LocalPlayer():Armor() local wep = LocalPlayer():GetActiveWeapon():Clip1() if wep < 0 then wep = "" else surface.SetTextColor( 255, 255, 255, 255) surface.SetTextPos( 420, 735 ) surface.SetFont( "Myfont" ) surface.DrawText( "Magazine: "..wep) // Ammo clip end surface.SetTextColor( 255, 255, 255, 255) surface.SetTextPos( 20, 735 ) surface.SetFont( "Myfont" ) surface.DrawText( "Health: "..HP) // Health surface.SetTextColor( 255, 255, 255, 255) surface.SetTextPos( 240, 735 ) surface.SetFont( "Myfont" ) surface.DrawText( "Armor: "..ARM) //Armor end[/CODE] I tried to remove it but that just breaks the HUD all together, any help please? Thank you, Strikerz
Here you go: [lua] function GM:HUDPaint() self.BaseClass:HUDPaint() local ply = LocalPlayer() local HP = LocalPlayer():Health() local ARM = LocalPlayer():Armor() local wep = LocalPlayer():GetActiveWeapon(); if( wep:IsValid() ) then wep = wep:Clip1(); end if wep < 0 then wep = "" else surface.SetTextColor( 255, 255, 255, 255) surface.SetTextPos( 420, 735 ) surface.SetFont( "Myfont" ) surface.DrawText( "Magazine: "..wep) // Ammo clip end surface.SetTextColor( 255, 255, 255, 255) surface.SetTextPos( 20, 735 ) surface.SetFont( "Myfont" ) surface.DrawText( "Health: "..HP) // Health surface.SetTextColor( 255, 255, 255, 255) surface.SetTextPos( 240, 735 ) surface.SetFont( "Myfont" ) surface.DrawText( "Armor: "..ARM) //Armor end [/lua]
Thank you soo much!
No problem.
Sorry, you need to Log In to post a reply to this thread.