Why isn't my debounce working?

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

is this supposed to be your debounce?
plane.CanF.Value = “false”

if so, change this line
if CanFireGuns.Value == “true” then

to be
if CanFireGuns.Value == “true” and plane.CanF.Value == “true” then

also… if you want to use boolean, for true and false
just use true, and false, not “true” and “false” because if CanFireGuns is a Bool Value and not a String Value then that might be a problem also

1 Like

Alright, I need to go right now.
I will use your suggestions, thanks for it. :smiley: