Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I add a Cooldown to my Dash Script?

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)

5 comments

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)

0

what kind of variable?

0

you didn't write this script did you....

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!

0

Please do some research it seems ur a beginner.

1 answer

✓ Accepted answer

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)

2 comments

0

Thanks dude! It worked! So all I had to do was insert debounce? I got to look into it.

0

No problem. And yes, you just have to use a debounce.

This discussion is preserved as it was. New answers, comments, and votes are closed.