I am making one gun and I want to put cooldown on it I tried something like this:
local cooldown = 5
local isCoolingDown = false
[...] -- some scripts parts--
--shoothing function--
button1DownListener = Mouse.Button1Down:Connect(function()
isCoolingDown = true
if tool.Ammo.Value > 0 then
debounce = true
RemoteEvent:FireServer(tool.BulletLocation.Position, tool.BulletLocation.Orientation, Mouse.Hit.p)
Gun_Sound:Play()
Shoot:Play()
tool.Ammo.Value = tool.Ammo.Value - 1
else
Empty_Sound:Play()
Shoot:Play()
end
wait(cooldown)
isCoolingDown = false
end)
What is wrong? I dont understand.
You aren’t checking if IsCoolingDown = true.
And, do you have a variable called debounce?
kboy100
(kboy100)
#3
Isn’t the variable isCoolingDown your debounce?
Try adding something like this:
local isCoolingDown = false
local coolDown = 5
if not isCoolingDown then
isCoolingDown = true
wait(coolDown)
isCoolingDown = false
end
1 Like
Daronion
(Daronion)
#4
Change to:
button1DownListener = Mouse.Button1Down:Connect(function()
if isCoolingDown then return end
isCoolingDown = true
if tool.Ammo.Value > 0 then
debounce = true
RemoteEvent:FireServer(tool.BulletLocation.Position, tool.BulletLocation.Orientation, Mouse.Hit.p)
Gun_Sound:Play()
Shoot:Play()
tool.Ammo.Value = tool.Ammo.Value - 1
else
Empty_Sound:Play()
Shoot:Play()
end
wait(cooldown)
isCoolingDown = false
end)
2 Likes
you arent really checking if the cooldown is equal to false,
you should make this instead:
local cooldown = 5
local isCoolingDown = false
[…] – some scripts parts–
–shoothing function–
button1DownListener = Mouse.Button1Down:Connect(function()
if CoolingDown == false then
isCoolingDown = true
if tool.Ammo.Value > 0 then
debounce = true
RemoteEvent:FireServer(tool.BulletLocation.Position, tool.BulletLocation.Orientation, Mouse.Hit.p)
Gun_Sound:Play()
Shoot:Play()
tool.Ammo.Value = tool.Ammo.Value - 1
else
Empty_Sound:Play()
Shoot:Play()
end
wait(cooldown)
isCoolingDown = false
end
end)
Yes I have debounce variables in my scripts.
Oh ok… I have to change the variable I did before something like wait(5)
(the cooldown variable is “isCoolingDown” and not “db”)
Thank you and thanks for everyone how replied too and sorry for the delay.
2 Likes