Gun not working correctly?

Tried creating a gun. I did it, but there is a bug. So whenever you shoot the gun, it wastes 1 bullet, obviously, and when the gun has 0 bullets, it reloads of course. BUT, wheneveryou unequip the weapon and re equip it, whenever you shoot, you lose and extra bullet. Lets say the gun wastes 1 bullet when shot, i unequip, then re equip, and then the gun starts losing 2 bullets per shot? I do that again, then it starts wasting 3 bullets per shot. I’m guessing the bug is somewhere right here? Here is the local script:

script.Parent.Activated:Connect(function()

if enabled == true then

  	wait(.2)
  	script.Parent.Fire:FireServer(mouse.Hit.p)
  	tool.Handle.Fire:Play()
  	maxAmmo.Value -= 1

  	local LoadHumAnim = Humanoid.Animator:LoadAnimation(script.Fire)
  	LoadHumAnim:Play()

  	if maxAmmo.Value < 1 then
  		enabled = false
  		tool.Handle.Reload:Play()
  		local LoadHumAnim = Humanoid.Animator:LoadAnimation(script.Reload)
  		LoadHumAnim:Play()

  		wait(2.2)
  		maxAmmo.Value = 10
  		enabled = true
  		

  	
  end

Hmm, that’s strange. Is the script.Parent.Activated function inside of another function? If the code you showed was inside of a Tool.Equipped function you would get the problem that you stated.

1 Like

Oh! You’re totally correct. It was inside an equipped function. Thank you so much!

No problem, glad I could help :slight_smile:!

1 Like