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)
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)