Cooldown Not Working

Why does my cooldown not work

local UIS = game:GetService(“UserInputService”)
local Rep = game:GetService(“ReplicatedStorage”)
local Remote = Rep:WaitForChild(“FireBall”)
local Plr = game:GetService(“Players”).LocalPlayer
local Mouse = Plr:GetMouse()
local debounce = false

UIS.InputBegan:Connect(function(input,gameproc)
if not gameproc then
if input.KeyCode == Enum.KeyCode.Q then
local Anim = Plr.Character.Humanoid:LoadAnimation(script.Animation)
Anim:Play()
delay(.8,function()
Remote:FireServer(Mouse.Hit.p)
Anim:Stop()
end)
if not debounce then
debounce = true
end
end
end

end)
Remote.OnClientEvent:Connect(function()
wait(10)
debounce = false
end)

Your debounce if statement needs to surround the code you are debouncing.

do i have to surround the Remote:FireServer?

Yes, you should do that or the player can queue up a bunch of “reloads” and start firing faster.

Can you show an example of how i would do it

oh never mind thank you so much

oye pon el codigo asi :
Sin título

local UIS = game:GetService(“UserInputService”)
local Rep = game:GetService(“ReplicatedStorage”)
local Remote = Rep:WaitForChild(“FireBall”)
local Plr = game:GetService(“Players”).LocalPlayer
local Mouse = Plr:GetMouse()
local debounce = false

UIS.InputBegan:Connect(function(input,gameproc)
	if not gameproc then
		if input.KeyCode == Enum.KeyCode.Q then
				if not debounce then
					debounce = true
					local Anim = Plr.Character.Humanoid:LoadAnimation(script.Animation)
					Anim:Play()
					delay(.8,function()
						Remote:FireServer(Mouse.Hit.p)
						Anim:Stop()
				end)
			end
		end
	end
end)

Remote.OnClientEvent:Connect(function()
	wait(10)
	debounce = false
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.