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

How to make a dash have a cooldown?

Asked by 5 years ago
local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()

local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=1824890937"

mouse.KeyDown:connect(function(key)
    if string.byte(key) == 50 then
        local playAnim = humanoid:LoadAnimation(anim)
        playAnim:Play()
        script.Sound:Play()
        player.Character.HumanoidRootPart.Velocity = player.Character.HumanoidRootPart.CFrame.lookVector * 135
        wait(2.0)
    end
    wait(10)
end)

How do I make this have a cooldown Quite difficult for me but it's such a simple script.

0
Use a debounce...https://developer.roblox.com/en-us/articles/Debounce ForeverBrown 356 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

In Roblox we can use something called a debounce a debounce is a bool value that checks to see if that value is true or not. You can name the value to whatever you want:

We`re gonna name it "debounce"

debounce = false --We set it to false because right now we have no cooldown

After we made a debounce bool value were gonna get into our code:

debounce = false --Were gonna put it in here

mouse.KeyDown:connect(function(key)

    if string.byte(key) == 50 and debounce == false then --Were gonna check if its false, and if it is then we "allow" it to do the action it must do

        debounce = true --We set it to true untill we set it to false again

        local playAnim = humanoid:LoadAnimation(anim)
        playAnim:Play()
        script.Sound:Play()
        player.Character.HumanoidRootPart.Velocity = player.Character.HumanoidRootPart.CFrame.lookVector * 135
        wait(2.0)
    end
    wait(10)

    debounce = false --(you can have your debounce here or somewhere else, depends on how long you want your cooldown to be. We have a "wait(10)" so the cooldown will end after 10 seconds

end)

Hope this helped :)

0
Sorry for my laziness :) ForeverBrown 356 — 5y
Ad

Answer this question