I've recently come across a problem where when the player attempts to shoot a shotgun when it's still empty, reloading will not disable the debounce I've set in place in order to prevent the shotgun from firing again.
local Ammo = 2
I've set a script wide local that determines what value the ammo is.
local debounce = false
local cooldownTime = 0.7
script.Parent.Activated:Connect(function()
if not debounce then
debounce = true
local shooting = game:GetService("Players").LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Shoot)
local sound = game:GetService("StarterPack").Shotgun.shooting
sound:Play()
shooting:Play()
Ammo = Ammo - 1
wait(cooldownTime)
debounce = false
if Ammo <= 0 then
debounce = true
elseif Ammo == 1 or Ammo == 2 then
debounce = false
end
end
end)
The above script is how the player shoots the shotgun.
script.Parent.Equipped:Connect(function(mouse)
mouse.KeyDown:Connect(function(key)
if key:lower() == "r" or key:upper() == "R" then
Ammo = Ammo+2
end
end)
end)
The script above is what I'm using to refill the ammo value.
I do believe that it has to do with the 'Ammo' variable constantly being subtracted into the negatives whenever the player shoots the shotgun. Any tips, suggestions, or help is appreciated!

1 comment
Maybe do: if Ammo <= 0 then Ammo = 0 end | This resets the ammo value?