-- local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local rootPart = character:WaitForChild("HumanoidRootPart")
local db = false
local cooldown = 5
local keysPressed = {}
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
keysPressed[input.KeyCode] = true
if not db then
if keysPressed[Enum.KeyCode.A] and keysPressed[Enum.KeyCode.Q] then
rootPart.Velocity = rootPart.CFrame.LookVector * Vector3.new(-150, 0, 0)
db = true
task.wait(cooldown)
db = false
elseif keysPressed[Enum.KeyCode.D] and keysPressed[Enum.KeyCode.Q] then
rootPart.Velocity = rootPart.CFrame.LookVector * Vector3.new(150, 0, 0)
db = true
task.wait(cooldown)
db = false
elseif keysPressed[Enum.KeyCode.Q] then
rootPart.Velocity = rootPart.CFrame.LookVector * -150
db = true
task.wait(cooldown)
db = false
end
end
end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessed)
if not gameProcessed then
keysPressed[input.KeyCode] = false
end
end)
Instead of using the HumanoidRootPart’s LookVector you could use the Humanoid MoveDirection that way it will consider the direction the player is wanting to move.
You could also add a check to see if the MoveDirection’s magnitude is 0 and default to the normalized forward direction (which is 0,0,-1). That will allow the player to dash forward when still
The issue with your current implementation is the misuse of the LookVector and combination of directions.
You should be using RightVector and LookVector correctly for direction.
You need to adjust the velocity to take into account the proper combination of directions.
I’ve tested this in Studio. Let me know if this is what you were looking for:
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local rootPart = character:WaitForChild("HumanoidRootPart")
local db = false
local cooldown = 5
local keysPressed = {}
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
keysPressed[input.KeyCode] = true
if not db then
if keysPressed[Enum.KeyCode.A] and keysPressed[Enum.KeyCode.Q] then
-- Dash left
rootPart.Velocity = rootPart.CFrame.RightVector * -150
db = true
task.wait(cooldown)
db = false
elseif keysPressed[Enum.KeyCode.D] and keysPressed[Enum.KeyCode.Q] then
-- Dash right
rootPart.Velocity = rootPart.CFrame.RightVector * 150
db = true
task.wait(cooldown)
db = false
elseif keysPressed[Enum.KeyCode.Q] then
-- Dash backward
rootPart.Velocity = rootPart.CFrame.LookVector * -150
db = true
task.wait(cooldown)
db = false
end
end
end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessed)
if not gameProcessed then
keysPressed[input.KeyCode] = false
end
end)