The second version I recommend is with ContextActionService, which allows you to bind and unbind action, so you can basically disable the dash if you need to :
local CAS = game:GetService('ContextActionService')
local Player = game:GetService('Players').LocalPlayer
repeat task.wait() until Player.Character
local Character = Player.Character
local HumanoidPart = Player.Character:WaitForChild("HumanoidRootPart") -- Find the Root Part of the Character
local Humanoid = Player.Character:WaitForChild("Humanoid") -- Find the Humanoid of the Character
local Gravity = workspace.Gravity
-- Modified the variables a bit so it worked properly
local DashTime = 0.2 -- Time the force apply
local Amount = 400 -- Dash force
local Cooldown = false -- Cooldown Lock
local CooldownTime = 2 -- Cooldown Time
local function Dash(actionName, inputState, inputObject)
if actionName == "Dash" and inputState == Enum.UserInputState.Begin and Cooldown == false then
Cooldown = true -- I prefer to always put the variable lock on top
local CharacterOrientation = math.rad(HumanoidPart.Orientation.Y - 180) -- Find the orientation of it
-- It was backward for some reason so I just subtract 180 degres
local DashVelocity = Vector2.new(
math.sin(CharacterOrientation),
math.cos(CharacterOrientation)) * Amount -- With a little bit of math, there is the dash velocity stored in a vector 2
script.Dash:Play() --I don't have the script.Dash so I trust you on that one
if Humanoid.FloorMaterial ~= Enum.Material.Air then
HumanoidPart:ApplyImpulse(Vector3.new(0,2000,0)) -- Makes the character airborn
wait()
end
HumanoidPart.AssemblyLinearVelocity = Vector3.new(0,0,0) -- Freeze the player in the air
workspace.Gravity = 0 -- Temporaly remove gravity (linear dash effect)
for i = DashTime * 20, -1, -1 do -- For the time give (put DashTime = 0 to be instant)
HumanoidPart:ApplyImpulse(Vector3.new(DashVelocity.X,0,DashVelocity.Y)) -- here we apply the velocity to the root part
task.wait(1/20)
end
workspace.Gravity = Gravity -- puts normal gravity back
task.wait(CooldownTime)
Cooldown = false
print("Good to go")
end
end
CAS:BindAction("Dash",Dash,Enum.KeyCode.G)
-- if you need to unbind the action use CAS:UnbindAction("Dash")