I am working on getting a hud displayed and the code below works; however, when I die it causes an error and the hud disappears until I reset the gamemode. It says that client:GetActiveWeapon():Clip1() is a nil value and the hook couldn’t run.
To me it sounds like when I die it is trying to set mag_left equal to my ActiveWeapon():Clip1(), but since I am dead I don’t have a Clip1(). What confuses me is that if I am dead the function should end at my if !client:Alive() then return end and it shouldn’t run the mag_left = Clip1() code.
Anyone have any suggestions or tips as to why this may be causing an error?
function player_hud() if !client:Alive() then return end local mag_left = client:GetActiveWeapon():Clip1() end
Also, is there a way to get a clip size of a weapon? I am working on getting a bar that decreases as you shoot, but I need the max amount of ammo in the clip size. I looked it up and I can find the current ammo and secondary, but i didn’t find anything that said clip size.
I wanted to stay away from creating an if statement for each weapon and defining the clipsize manually, however if that is the only way to do it then I will do it that way. I am open for some suggestions on that I guess.