0

# Why does my gun stop firing if i use debounce and shoot behind me ?

Edited 12 days ago

the gun script has magnitude < 1.33 in it and it makes it so that when you shoot behind you, the gun doesnt shoot. i added a debounce to the gun script and it works until you shoot behind or to the side of your character it stops shooting and it doesnt let you shoot forward again. it used to let you shoot forward again without debounce. i wanna keep the debounce so the gun can have a cooldown so it isnt spam fired. you have to re-equip the gun for it to shoot again, but it still breaks if you shoot to the side or behind your character.

Here is some of the script that is probably breaking the gun.

tool.Equipped:Connect(function(mouse)
gungui:Clone().Parent = player.PlayerGui
findBodyType()
equipAnimation:FireServer(tool.ShootAnim)
mouse.Icon = "rbxassetid://7262331135"
local debounce = false
mouse.Button1Down:Connect(function()
else
if not debounce then
debounce = true
local ray = Ray.new(tool.Handle.CFrame.p,(player:GetMouse().Hit.p - tool.Handle.CFrame.p).unit*300)
local part,position = game.workspace:FindPartOnRay(ray,player.Character,false,true)
if difference.magnitude < 1.33 then
gunshotSound:Play()
shootevent:FireServer(tool,position,part)
bullets.Value = bullets.Value - 1
wait(1)
debounce = false
end
end
end
end)

0
That happens because you do not reset the debounce. A debounce should not be used to do what you wish, either. A simple conditional will do Ziffixture 6863 — 12d
0
FYI, each time you equip your gun you will multiply your Button1Down response—3 equips will shoot your gun 3 times, etc... You can resolve this by just using Tool.Activated Ziffixture 6863 — 12d
0
workspace:Raycast has also superseded this method of ray-casting. Ziffixture 6863 — 12d