Issue with Dash/Side Dash

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am making a battlegrounds game and I added a dashing system which dashes to a different direction depending on which key you hold before pressing q.
  2. What is the issue? Include screenshots / videos if possible!
    When pressing to keys at once, or releasing a key for a very short period of time it doesn’t work, sometimes the key press doesn’t even register.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried several different mechanics and searched over the devforum.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local script in starter character scripts

local UserInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local dashAnimation = workspace.DashAnimation
local dashAnimationTrack = humanoid:LoadAnimation(dashAnimation)
local canDash = true
local cooldown = 5

local keyDown = nil
UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then 
		return 
	end
	if not canDash then 
		return 
	end
	
	if input.KeyCode == Enum.KeyCode.Q then
		canDash = false
		dashAnimationTrack:Play()
		
		local dash = Instance.new("BodyVelocity")
		dash.MaxForce = Vector3.new(1,0,1) * 30000
		
		if keyDown == "W" then

			dash.Velocity = character.HumanoidRootPart.CFrame.lookVector * 100
		elseif keyDown == "S" then

			dash.Velocity = character.HumanoidRootPart.CFrame.lookVector * 75 * -1
		elseif keyDown == "A" then

			dash.Velocity = character.HumanoidRootPart.CFrame.RightVector * 50 * -1
		elseif keyDown == "D" then

			dash.Velocity = character.HumanoidRootPart.CFrame.RightVector * 50
		else

			dash.Velocity = character.HumanoidRootPart.CFrame.lookVector * 100
		end
		dash.Parent = character:WaitForChild("HumanoidRootPart")
		
		for i=1, 8 do
			wait(0.1)
			dash.Velocity *= 0.7
		end
		dashAnimationTrack:Stop()
		dash:Destroy()
		task.wait(cooldown)
		canDash = true
	elseif input.KeyCode == Enum.KeyCode.W then
		keyDown = "W"
	elseif input.KeyCode == Enum.KeyCode.A then
		keyDown = "A"
	elseif input.KeyCode == Enum.KeyCode.S then
		keyDown = "S"
	elseif input.KeyCode == Enum.KeyCode.D then
		keyDown = "D"
	end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.W then
		keyDown = nil
	elseif input.KeyCode == Enum.KeyCode.A then
		keyDown = nil
	elseif input.KeyCode == Enum.KeyCode.S then
		keyDown = nil
	elseif input.KeyCode == Enum.KeyCode.D then
		keyDown = nil
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Your problem is that, when your input has ended your “keyDown” is set to nil during runtime.
It’s likely that this is the cause of your problems.

Instead of mapping keydown to a bool you should use a table so that said keydown doesn’t get overridden during runtime, or use “GetKeysPressed” to check what direction they should be dashing to.

1 Like

i would use get keys pressed but I need the latest key pressed. for example if youre holding w and than you press d i want to dash to the direction d btw i set it to nil because theres an else statement at the end so if its nil you do default forward dash

Most dashes have omnidirectional dashing, why would you prefer a singular direction? And either way it’d be easier to implement omnidirectional dashing over the most current.

1 Like

most games like tsb have only side/back/forward dashing. thank you though i just joined and realized some dashes have prioritys for example if youre holding w and d it does a forward dash anyways

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.