This debounce just doesn’t seem to work. If you click too quickly, the debounce just fails.
Why?
local damage = {}
local config
local debounce = false
function damage.IdentifyGun(gunname, target)
config = script.Configuration
local folder = config:FindFirstChild(gunname)
local damagevar = folder.Damage
local ammovar = folder.Ammo
local fireratevar = folder.FireRate
local reloadtimevar = folder.ReloadTime
local maxammovar = folder.MaxAmmo
if target == nil then
return
end
if target.Parent:FindFirstChild("Humanoid") then
if debounce == false then
if ammovar.Value > 0 then
debounce = true
ammovar.Value -=1
target.Parent.Humanoid:TakeDamage(damagevar.Value)
task.wait(fireratevar.Value)
if ammovar.Value == 0 then
debounce = true
task.wait(reloadtimevar)
debounce = false
return
end
end
end
end
end
function damage.Effect(muzzleeffect)
muzzleeffect.Enabled = true
task.wait(.25)
muzzleeffect.Enabled = false
end
return damage
Before return at “if ammovar.Value == 0” try to print debounce. Does it give false, or doesnt give anything?
If it doesnt give anything, it seems like a problem with task.wait, experienced by myself in past.
Did a bit of changes and tried what you did, it seems like there’s ANOTHER problem
local damage = {}
local config
local debounce = false
function damage.IdentifyGun(gunname, target)
config = script.Configuration
local folder = config:FindFirstChild(gunname)
local damagevar = folder.Damage
local ammovar = folder.Ammo
local fireratevar = folder.FireRate
local reloadtimevar = folder.ReloadTime
local maxammovar = folder.MaxAmmo
if target == nil then
return
end
if target.Parent:FindFirstChild("Humanoid") then
if debounce == false then
if ammovar.Value > 0 then
print("aaq")
debounce = true
ammovar.Value -=1
print(ammovar.Value)
target.Parent.Humanoid:TakeDamage(damagevar.Value)
task.wait(fireratevar.Value)
if ammovar.Value == 0 then
debounce = true
task.wait(reloadtimevar.Value)
print("mhmn")
print(debounce)
debounce = false
return
end
end
end
end
end
function damage.Effect(muzzleeffect)
muzzleeffect.Enabled = true
task.wait(.25)
muzzleeffect.Enabled = false
end
return damage
It seems to be that ammovar.Value > 0 only runs once?
I’m not sure why and ammovar is not 0, it’s 31 as it only runs once like I said
Try printing reloadtimevar to see what your task.wait time is being set to. If the script isn’t getting the right number then it might be setting it to 0. reloadtimevar has to be a decent time, not something low like .1
But that’s what I want you to check with the print statement, to see if it’s getting the right value. If the value is incorrect (like 0) then your debounce is useless.
Instead of task.wait(fireratevar.Value) you could easily change it to task.wait(5) so when you test you can see if the debounce works properly.