Hello.
Please help me with a debounce.
local function FireGuns(target)
if CanFireGuns.Value == "true" then
plane.CanF.Value = "false"
for _,v in pairs(plane:GetDescendants()) do
if v.Name == "MachineGun" then
local p = v.Orientation
local bullet = bu:Clone()
bullet.Position = v.Position
bullet.Orientation = Vector3.new(math.random(p.X-spread,p.X+spread),math.random(p.Y-spread,p.Y+spread),math.random(p.Z-spread,p.Z+spread))
bullet.Parent = workspace
wait(GunFireRate)
plane.CanF.Value = "true"
end
end
end
end
local function FireBoth(nearestEnemy)
local distance = (plane.PrimaryPart.Position - nearestEnemy.PrimaryPart.Position).magnitude
if distance <= 1001 then
if GunFireRate ~= 0 then
task.spawn(FireGuns)
end
if CannonFireRate ~= 0 then
task.spawn(FireCannons)
end
end
end
This is how the code is run:
A while true loop with a forloop through a folder of aircraft runs this code.
The problem: The guns spew out bullets at a ridicoulous pace.
What I want:
Make the machine guns only shoot at GunFireRate