Trying to make a dash system

  1. What do you want to achieve? I want to make a dash (dodge) system that if you press S and the dash key at the same time you dash back, but if you just press the dash key you go forward.

  2. What is the issue? The script only detects when the player press the dash key and not the S + dash key.

  3. What solutions have you tried so far? I looked and searched on DevForum but I didn’t find a solution.

Video showing the issue:
robloxapp-20220713-0023164.wmv (1.2 MB)

Script below:

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local UIS = game:GetService("UserInputService")
local Debounce = false
local keybind = player:WaitForChild("Config").Dash 
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://8492933955"
local playAnim = humanoid:LoadAnimation(anim)

UIS.InputBegan:Connect(function(key, IsTyping)
	if IsTyping then
		return
	else
		if UIS:IsKeyDown(Enum.KeyCode[keybind.Value]) then
			if Debounce == false then
				if script.Parent.Parent.Parent.PlayerValues.Stunned.Value == false then
					local State = player.Character.Humanoid:GetState()
					if State == ("Enum.HumanoidStateType.Dead") then
						return
					else
						Debounce = true
						playAnim:Play()
						local Sortear = math.random(1,3)
						if Sortear == 1 then
							script.Sound.PitchShiftSoundEffect.Enabled = false
							script.Sound:Play()
						elseif Sortear == 2 then
							script.Sound.PitchShiftSoundEffect.Octave = 1.05
							script.Sound.PitchShiftSoundEffect.Enabled = true
							script.Sound:Play()
						elseif Sortear == 3 then
							script.Sound.PitchShiftSoundEffect.Octave = 1.1
							script.Sound.PitchShiftSoundEffect.Enabled = true
							script.Sound:Play()
						end
						
						player.Character.HumanoidRootPart.Velocity = player.Character.HumanoidRootPart.CFrame.lookVector * 135
						local cd = script:WaitForChild("Dash"):Clone()
						cd.Parent = script.Parent.Parent.Parent.RightFoot
						cd:Emit(10)
						cd.Enabled = true
						spawn(function()
							wait(0.5)
							cd.Enabled = false
							cd:Destroy()
						end)
						wait(3)
						playAnim:Stop()
						Debounce = false
					end
				end
			end	
		elseif UIS:IsKeyDown(Enum.KeyCode[keybind.Value]) and UIS:IsKeyDown(Enum.KeyCode.S) then
			if Debounce == false then
				if script.Parent.Parent.Parent.PlayerValues.Stunned.Value == false then
					local State = player.Character.Humanoid:GetState()
					if State == ("Enum.HumanoidStateType.Dead") then
						return
					else
						Debounce = true
						playAnim:Play()
						local Sortear = math.random(1,3)
						if Sortear == 1 then
							script.Sound.PitchShiftSoundEffect.Enabled = false
							script.Sound:Play()
						elseif Sortear == 2 then
							script.Sound.PitchShiftSoundEffect.Octave = 1.05
							script.Sound.PitchShiftSoundEffect.Enabled = true
							script.Sound:Play()
						elseif Sortear == 3 then
							script.Sound.PitchShiftSoundEffect.Octave = 1.1
							script.Sound.PitchShiftSoundEffect.Enabled = true
							script.Sound:Play()
						end

						player.Character.HumanoidRootPart.Velocity = player.Character.HumanoidRootPart.CFrame.lookVector * -135
						local cd = script:WaitForChild("Dash"):Clone()
						cd.Parent = script.Parent.Parent.Parent.RightFoot
						cd:Emit(10)
						cd.Enabled = true
						spawn(function()
							wait(0.5)
							cd.Enabled = false
							cd:Destroy()
						end)
						wait(3)
						playAnim:Stop()
						Debounce = false
					end
				end
			end	
		end
	end
end)

2 Likes

the velocity should be based on the humanoids move direction

replace

player.Character.HumanoidRootPart.Velocity = player.Character.HumanoidRootPart.CFrame.lookVector * -135

with

player.Character.HumanoidRootPart.Velocity = player.Character.Humanoid.MoveDirection * 135

see if that works :smiley:

3 Likes

I changed but it still didn’t work. I did put a print in the script if the script detects the 2 keys being pressed (Detect1 to the first If [ if UIS:IsKeyDown(Enum.KeyCode[keybind.Value]) then ] as you can see in the script and Detect2 to the second if [ elseif UIS:IsKeyDown(Enum.KeyCode[keybind.Value]) and UIS:IsKeyDown(Enum.KeyCode.S) then ]) and only Detect1 has been printed. This means that the script is not getting the two keys being pressed.

2 Likes
local userInputService = game:GetService("UserInputService")

local Input = {}
local binds = {}
 
function Input.BindKeyPresses(name, callback, ...)

    local keys = table.pack(...)
    keys.n = nil

    binds[name] = userInputService.InputBegan:Connect(function(input)
        if input.KeyCode and input.KeyCode == keys[#keys] then
            for i, key in pairs(keys) do 
                if not userInputService:IsKeyDown(key) then

                    return
                end
            end
            callback()
        end
    end)
end

return Input

The first parameter is just a name so you add it to the table, the second is the function that will happen if he pressed all the buttons and everything after are the keybinds you want to set

1 Like

Using simple velocity wont be a good idea as it doesn’t push that well. Use BodyVelocity like this.

local velocity = player.Character.Humanoid.MoveDirection * 135
local bv = Instance.new("BodyVelocity",player.Character.HumanoidRootPart)
bv.Velocity = velocity
game:GetService("Debris"):AddItem(bv,0.1)
1 Like

I wrote a tutorial-resource for dashing, unsure how you couldn’t find it by searching

1 Like

I really haven’t found it. But even if I found it, I probably wouldn’t understand it because I’m not a very advanced scripter.

1 Like