I am working on dash system. However, when I tested my dash system, I found an issue.
It’s not about error. When I dash, there will be a 3 second cooldown until I will be able to dash again.
However, while the cooldown, when I click Q+D for dash, my character stops moving for a few seconds. When I start to spam click to Q+D to dash, I completely cannot move until I stop clicking. Why is that happening any ideas?
Here is my script.
Script: Local Script
Location: StarterCharacterScript
Note: I user LinearVelocity for my dash to work.
local plr = game.Players.LocalPlayer
local chr = script.Parent
local Root = chr:WaitForChild("HumanoidRootPart")
local Hum = chr:WaitForChild("Humanoid")
local User = game:GetService("UserInputService")
local DashEvent = game.ReplicatedStorage["Dash Event"]
local Air = Enum.Material.Air
local BinFunc = script.Parent
local RightLeft_Dash = false
local Controls = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
local Vel
User.InputBegan:Connect(function(key, processed)
if processed then return end
if key.KeyCode == Enum.KeyCode.Q then
Vel = Instance.new("LinearVelocity", Root)
local Attach = Instance.new("Attachment", Root)
Vel.MaxForce = math.huge
Vel.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
Vel.Attachment0 = Attach
Vel.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
Attach.WorldPosition = chr:FindFirstChild("HumanoidRootPart").AssemblyCenterOfMass
if User:IsKeyDown(Enum.KeyCode.D) and RightLeft_Dash == false then
RightLeft_Dash = true
if Hum.FloorMaterial == Air then
Vel.VectorVelocity = Vector3.new(73,-28,0)
DashEvent:FireServer("Right Dash")
else
Vel.VectorVelocity = Vector3.new(73,0,0)
DashEvent:FireServer("Right Dash")
end
task.spawn(function()
task.wait(3)
RightLeft_Dash = false
end)
end
game.Debris:AddItem(Vel, 0.2)
game.Debris:AddItem(Attach, 0.2)
end
end)
User.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.D and Vel then
Vel.VectorVelocity = Vector3.new(0,0,0)
end
end)
Here is the video proof what I am talking about.
My character stops automatically when I click a key on my keyboard.