Double Tap W To Sprint

For a few weeks now, I’ve been trying to find a tutorial on how to make a system like double tap W to sprint, but I couldn’t. So, that’s why I’m here making a post about it. If anybody has a video that works or could just paste a script with explanations, then I would heavily appreciate it.

3 Likes

Double Tap W To SPRINT | How to Make Your Own Roblox Demon Slayer Game | Part 2 - YouTube I found it on the first result on google.

1 Like

Yep, I’ve already tried that video. I figured it was just outdated or something since it didn’t work.

Have you tried this one? HOW TO MAKE DOUBLE TAP W TO RUN | Roblox Scripting Tutorial + [MODEL GIVEAWAY] - YouTube

1 Like

I feel like I have, but I’m not quite sure. I’ll give it a try.

Explanation


Using ticks we can determine how long since the last time the player pressed W. If it’s below the cooldown it will activate sprinting for the player. If you want a line-by-line explanation of this script just tell me.

Full script:


-- Add this inside StarterCharacterScripts and LocalScript

local Player = {
	["Player"] = game.Players.LocalPlayer,
	["Character"] = script.Parent,
	["Humanoid"] = script.Parent:WaitForChild("Humanoid"),
}

local Speeds = {
	["Normal"] = 16,
	["Extra"] = 32,
}

local Debounces = {
	["MaxTicks"] = 0.2,
	["Cooldown"] = 0,
	["Debounce"] = false,
	["Running"] = false,
	["LastTime"] = tick()
}

local Services = {
	["UIS"] = game:GetService("UserInputService")
}

Services.UIS.InputBegan:Connect(function(input, isTyping)
	if isTyping then return end

	if input.KeyCode == Enum.KeyCode.W then
		if not Debounces.Debounce and not Debounces.Running then

			if tick() - Debounces.LastTime  <= Debounces.MaxTicks then
				Debounces.Debounce = true
				Debounces.Running = true

				Player.Humanoid.WalkSpeed = Speeds.Extra

				Debounces.LastTime = tick()


			else
				Debounces.LastTime = tick()

			end
		end
	end


end)


Services.UIS.InputEnded:Connect(function(input, isTyping)
	if isTyping then return end

	if Debounces.Running and input.KeyCode == Enum.KeyCode.W  then
		Debounces.Running = false

		Player.Humanoid.WalkSpeed = Speeds.Normal

		wait(Debounces.Cooldown)
		Debounces.Debounce = false
	end

end)
7 Likes
local cooldown = 1
local pressed_W_Again = false
local pressed_W_Once = false
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local hum = char.Humanoid
local sprint_value = 20

game:GetService("UserInputService").InputBegan:Connect(function(input, processed)
	
	if processed then return end -- processed is equal to true if the player is typing in a text box, the chat system, etc. We want the script to return so that the player doesn't enable sprinting while trying to do something else.
	
	if input.KeyCode == Enum.KeyCode.W and not pressed_W_Once then
		
		pressed_W_Once = true
		task.wait(cooldown) -- cooldown gives the player 1 second to press W another time.
		
		if pressed_W_Again then
			hum.WalkSpeed = sprint_value
		else -- resets and lets the player try again.
			pressed_W_Once = false
			pressed_W_Again = false
		end
		
	elseif input.KeyCode == Enum.KeyCode.W and pressed_W_Once then
		pressed_W_Again = true
	end
	
end)
1 Like

It didn’t work, I don’t know why, but thank you for trying to help!

Thank you for trying to help. This seems very useful, maybe I would use it for another game!

1 Like