A better way to check ammo amount?

When I deal with muzzle flare, I usually keep the muzzle flaring until the player stops holding down the mouse. But, the muzzle flare keeps going when the gun is not firing and is all out of ammo and the player is still holding down the mouse. I prevent this by having a wait loop that runs every millisecond or something.

The problem is, wait loops can take up a lot of memory and I want to look for a more efficient way of checking ammo. Here’s my code:

while wait() do
	if PrimaryCurrentAmmo < 1 then
	      --//Code here
	end
end

Any help would be greatly appreciated!

I’d suppose that you could use a Boolean to detect if there is ammo in the gun. I’m not sure if this would work well or at all but I think that you can give it a shot (pun intended).

Well, an if statement only runs once, therefore I would have to use another while wait loop.

Using the boolean just makes us have to use 2 wait loops instead of 1

Is it possible for you to share some of your other code where you detect if the mouse is being held

That is not relevant. I just want to find a better way to check if the mag is depleted