Re: Script can't detect the magazine
Try changing line 2 to:
Code:
local gun = ToHDFirearm(ToAHuman(actor).EquippedItem);
Right now it's probably treating it as a generic attachable or helddevice or whatever, something that doesn't have a magazine. Cast it to an HDFirearm before trying to access the magazine.
Also, I believe line 3 is incorrect, you can't create/access variables like that for an object*. You can see if it works as is, I may be misremembering now, but if it doesn't, try changing line 3 to:
Code:
local roundsInMag = gun.Magazine.RoundCount;
All subsequent calls for gun.roundsInMag would have to be replaced as well of course, though I see none here so I'm not sure what the point of that variable is.
*Technically you can with metatables and a bit of clever scripting, but I'm pretty sure you can't do it straightforwardly like this.