Im trying to make a dash system and cant do it normaly.
script:
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local rootpart = script.Parent.Parent:WaitForChild("HumanoidRootPart")
local animationController = game:GetService("Players").LocalPlayer.Character:WaitForChild("Humanoid"):WaitForChild("Animator")
local UIS = game:GetService("UserInputService")
--dash
local dashevent = game:GetService("ReplicatedStorage").Events.Dash
local animation = Instance.new("Animation")
local QW = false
local QS = false
local QA = false
local QD = false
--end
local animations = {
["DashFront"] = "rbxassetid://16566527703";
["DashLeft"] = "rbxassetid://16591663577";
["RightDash"] = "must be id here";
["DashDown"] = "must be id here";
}
local active = false
UIS.InputBegan:Connect(function(key, typing)
local dashanim = "Front"
if key.KeyCode == Enum.KeyCode.Q then
if key.KeyCode == Enum.KeyCode.W then
QW = true
dashanim = "Front"
elseif key.KeyCode == Enum.KeyCode.D then
QD = true
dashanim = "Left"
elseif key.KeyCode == Enum.KeyCode.A then
QA = true
elseif key.KeyCode == Enum.KeyCode.S then
QS = true
end
animation.AnimationId = animations["Dash"..dashanim]
local dashanimationTrack = animationController:LoadAnimation(animation)
local Attachment = Instance.new("Attachment", rootpart)
local BV = Instance.new("BodyVelocity", Attachment)
if dashanim == "Front" then
BV.MaxForce = Vector3.new(math.huge,0,math.huge)
BV.P = 9e9
BV.Parent = rootpart
BV.Velocity = rootpart.CFrame.LookVector * 45
task.wait(0.01)
dashanimationTrack:Play()
dashevent:FireServer(player)
dashevent.OnClientEvent:Connect(function(player, results)
BV:Destroy()
Attachment:Destroy()
end)
elseif dashanim == "Left" then
BV.MaxForce = Vector3.new(math.huge,0,math.huge)
BV.P = 9e9
BV.Parent = rootpart
BV.Velocity = rootpart.CFrame.RightVector * 45
dashanimationTrack:Play()
task.wait(0.3)
BV:Destroy()
Attachment:Destroy()
end
end
end)
UIS.InputEnded:Connect(function(key, typing)
if typing then return end
if key.KeyCode == Enum.KeyCode.W then
QW = false
elseif key.KeyCode == Enum.KeyCode.D then
QD = false
elseif key.KeyCode == Enum.KeyCode.A then
QA = false
elseif key.KeyCode == Enum.KeyCode.S then
QS = false
end
end)
One problem is when i pressing a Q and W animation W, but when i pressing Q and D animation W playing still