Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why my cooldown is not working properly?

Asked by 5 years ago

so the cooldown works only one time but it breaks after. some guy told me to make 2 debounces, 1 to make sure you don't deactivate the cooldown numerous times, and one for the actual cooldown but i don't really understand what i have to do since i am a beginner. Can someone help me?

local play = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local Character = play.Character or play.CharacterAdded:wait()
local a = script.Parent.Animations.Blocking  
local b = play.Character:WaitForChild("Humanoid"):LoadAnimation(a)
local debounce = false
local remote = game.ReplicatedStorage:WaitForChild("blockinge")
uis.InputBegan:Connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.F and not gameProcessed and not debounce then
        debounce = true
        remote:FireServer()
        b:Play()
    end    
end)

uis.InputEnded:Connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.F and not gameProcessed and debounce then
        b:Stop()
        wait(5)
        debounce = false
    end
end)

1 answer

Log in to vote
0
Answered by 5 years ago

No, you don't need a second debounce and I'm not sure what that person was thinking, the real problem here is that you are not setting the debounce back to false.

if input.KeyCode == Enum.KeyCode.F and not gameProcessed and not debounce then
    debounce = true
    remote:FireServer()
    b:Play()
    wait(1) -- This can be however long you want.
    debounce = false
end

Might I ask why you are doing the debounce on the client? This can be spoofed by exploiters and they will be able to cheat in your game, so I recommend doing the debounce on the server. (You will need to give each player their own debounce value to do this, and it will not be done in a local script.)

Ad

Answer this question