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

How do I add a Cooldown to my Dash Script?

Asked by
Fuhayy 2
4 years ago

I'm trying to add a cooldown to this dash script, but I don't know where to put wait() or where to make the cooldown.

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
local Time = 1
local anim = Instance.new("Animation")
anim.Parent = script.Parent
anim.AnimationId = "rbxassetid://4879489579"

UserInputService.InputBegan:Connect(function(Input, GameStuff)
    if GameStuff then return end
    if Input.KeyCode == Enum.KeyCode.Q then
        local track = Char:WaitForChild("Humanoid"):LoadAnimation(anim)
        Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.lookVector*150
        track:Play()
        wait(Time)  -- Do I put this here?
    end
-- or here?
end)
0
add a variable that is set to true on start, and disable on end, then put Time in wait and I don't think it matters where you put the wait(Time) Feroxidus 83 — 4y
0
what kind of variable? Fuhayy 2 — 4y
0
you didn't write this script did you.... Feroxidus 83 — 4y
0
I wrote the script, I rewrote what you sent me and then tested it out. The cooldown was too long so I reduced the Time to 0.5 secs, after I tested it it was perfect! Thank You! Fuhayy 2 — 4y
0
Please do some research it seems ur a beginner. JesseSong 3916 — 4y

1 answer

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

You have to use a debounce/cooldown. For more info click here.

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
local Time = 1
local anim = Instance.new("Animation")
anim.Parent = script.Parent
anim.AnimationId = "rbxassetid://4879489579"

local debounce = false

UserInputService.InputBegan:Connect(function(Input, GameStuff)
    if GameStuff then return end
    if Input.KeyCode == Enum.KeyCode.Q and not debounce then -- checks if debounce == false
        debounce = true -- sets debounce to true so the if statement does not run
            local track = Char:WaitForChild("Humanoid"):LoadAnimation(anim)
            Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.lookVector*150
            track:Play()
            wait(Time)  -- Do I put this here?
        debounce = false -- sets the debounce to false so the if states does run
    end
-- or here?
end)
0
Thanks dude! It worked! So all I had to do was insert debounce? I got to look into it. Fuhayy 2 — 4y
0
No problem. And yes, you just have to use a debounce. youtubemasterWOW 2741 — 4y
Ad

Answer this question