I’m having an issue with the dash function in my game. Specifically, when I try to dash in a certain direction and hit the opposite key, the dash won’t cancel and continues until it’s finished. How would I able to achieve this I am pretty confused on how to do this.
Here is the clip: I had troubles uploading clip, so I had to use a link instead.
External MediaIn the clip above, when I am dashing, I am clicking the Q and the D key to dash right, but when I click the A key while dashing I want it to cancel the roll.
Here is code if needed:
local Keybind = Enum.KeyCode.Q
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local Debounce = false
local DashTime = .2
local Cooldown = 1
local Force = 50
local Anims = {
["Left"] = Humanoid:LoadAnimation(script.Animations:WaitForChild("Left")),
["Right"] = Humanoid:LoadAnimation(script.Animations:WaitForChild("Right")),
["Forward"] = Humanoid:LoadAnimation(script.Animations:WaitForChild("Forward")),
["Back"] = Humanoid:LoadAnimation(script.Animations:WaitForChild("Back"))
}
UIS.InputBegan:Connect(function(Key)
if Key.KeyCode == Keybind then
if not Debounce then
Debounce = true
local Slide = Instance.new("BodyVelocity")
Slide.MaxForce = Vector3.new(1,0,1) * 20000
Slide.Velocity = Humanoid.MoveDirection * Force
Slide.Parent = Character.HumanoidRootPart
-- Playing animation depending on the key held
if UIS:IsKeyDown(Enum.KeyCode.W) then
Anims.Forward:Play()
elseif UIS:IsKeyDown(Enum.KeyCode.A) then
Anims.Left:Play()
elseif UIS:IsKeyDown(Enum.KeyCode.S) then
Anims.Back:Play()
elseif UIS:IsKeyDown(Enum.KeyCode.D) then
Anims.Right:Play()
end
wait(DashTime)
game.Debris:AddItem(Slide, 0.1)
wait(Cooldown)
Debounce = false
end
end
end)