Hey guys, I need some help with ma code. The script does the dashing really well. I can press double W, D, A or S to dash front, back, right, and left. But what i need help in is the cooldown, rn i can dash infinetly and its really goofy. What i also need some help is the dash sound, how can i add a sound when dash?
local Character = script.Parent;
local Humanoid = Character:WaitForChild("Humanoid");
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart");
local SideGyro = Instance.new("BodyGyro")
SideGyro.MaxTorque = Vector3.new(3e5,0,3e5)
SideGyro.P = 5e5
SideGyro.Parent = HumanoidRootPart
local RunService = game:GetService('RunService')
local UserInputService = game:GetService('UserInputService')
local Dashing = false
local DashSpeed = 45
local DoubleTaps = {2}
local Animations = {
["DashRight"] = 'rbxassetid://14168214362';
["DashLeft"] = 'rbxassetid://14168217110';
["DashFront"] = 'rbxassetid://14168318057';
["DashBack"] = 'rbxassetid://14168210966';
}
for i,v in pairs(Animations) do
local Anim = Instance.new("Animation")
Anim.AnimationId = v
Anim = Humanoid:LoadAnimation(Anim)
Animations[i] = Anim
end
function Dash(Key)
if Dashing then
return
end
local DashAnim = "Back"
local Front = -1
local Side = 0
if Key == Enum.KeyCode.A then
Side=-1
Front = 0
DashAnim = "Left"
end
if Key == Enum.KeyCode.D then
Side=1
Front = 0
DashAnim = "Right"
end
if Key == Enum.KeyCode.W then
Side=0
Front = 1
DashAnim = "Front"
end
if Key == Enum.KeyCode.S then
Side=0
Front = -1
DashAnim = "Back"
end
Dashing = true
Animations["Dash"..DashAnim]:Play()
local DashVelocity = Instance.new("BodyVelocity")
DashVelocity.MaxForce = Vector3.new(math.huge,0,math.huge)
DashVelocity.P = 9e9
DashVelocity.Parent = HumanoidRootPart
DashVelocity.Velocity = HumanoidRootPart.CFrame.LookVector * (Front * DashSpeed) + HumanoidRootPart.CFrame.RightVector * (Side * DashSpeed)
coroutine.wrap(function()
task.wait(1.5)
local DashEffect = game.ReplicatedStorage.DustTrail:Clone();
DashEffect.Parent = workspace;
if DashAnim == "Left" then
DashEffect.DustRight:Destroy();
DashEffect.CFrame = Character["Right Leg"].CFrame * CFrame.new(-1,0,-2);
else if DashAnim == "Right" then
DashEffect.DustLeft:Destroy();
DashEffect.CFrame = Character["Left Leg"].CFrame * CFrame.new(3,2,5);
else if DashAnim == "Front" then
DashEffect.DustLeft:Destroy();
DashEffect.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0,-1,3);
else
DashEffect.DustLeft:Destroy();
DashEffect.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0,-1,-.5);
end
end
end
for i,v in pairs(DashEffect:GetDescendants()) do
if not v:IsA("ParticleEmitter") then continue end
v:Emit(5);
end
game.Debris:AddItem(DashEffect, .5);
end)()
repeat wait() DashVelocity.Velocity = HumanoidRootPart.CFrame.LookVector * (Front * DashSpeed) + HumanoidRootPart.CFrame.RightVector * (Side * DashSpeed)
until not Animations["Dash"..DashAnim].IsPlaying
Dashing = false
DashVelocity:Destroy()
end
function LoadDoubleTap(Key,Funct)
DoubleTaps[Key] = tick()-10
UserInputService.InputBegan:Connect(function(Pressed,Typing)
if Pressed.KeyCode == Key then
if (tick() - DoubleTaps[Key]) < 1.5 then
Funct(Key)
else
DoubleTaps[Key] = tick()
end
end
end)
end
LoadDoubleTap(Enum.KeyCode.W,Dash)
LoadDoubleTap(Enum.KeyCode.A,Dash)
LoadDoubleTap(Enum.KeyCode.S,Dash)
LoadDoubleTap(Enum.KeyCode.D,Dash)