[SOLVED] Shotgun staying enabled for some reason

I was making an ammo counter on the UI but when I was doing that a part of the code was making the shotgun stay enabled. The main scripts are bullets, switch and maybe the gun-shoot scripts.
The project: PlayCanvas | HTML5 Game Engine

Hi @EXECUTABLE!

I assume the shotgun should be disabled when you run out of ammo?

Where do you enable and disable the shotgun?

when you press 2 to equip the pistol

while testing I found its more of an issue of the variable refusing to toggle back to pistol

it also seems to be an issue with bullets.js because when I disable it I do not have the issue

I see nothing in bullet.js that should effect this. The code in switch.js is all I can find where you enable and disable the gun entities.

I updated it a little and it’s still doing the same thing

whenever bullets is enabled the console logs shotgun

Why you set held to ‘null’ here in the update function?

image

it was a test

With bullets enabled:

With bullets disabled:

Then you should remove everything in the bullet.js script you don’t use, and disable lines temporarily to find out which line cause the problem.

somehow its the if statments

I see. Statement if (held = 'Pistol') { should be if (held === 'Pistol') {. Otherwise you probably change the variable in the statement.

It was because I had - instead of == I feel so dumb.