Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I stop the walkspeed of the character not decreasing after double tapping "W" ?

Iv'e changed up a double tap script so it plays an animation and changes the walkspeed. I found out that if I'm still hold W after double tapping then the walkspeed stays at 20 instead of reverting back to 16, I don't know how to fix this.

click = false
locplay = game.Players.LocalPlayer
human = locplay.Character.Humanoid
char = locplay.Character

local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://1453429139"

game:GetService("UserInputService").InputBegan:connect(function(input1)
	if input1.KeyCode == Enum.KeyCode.W then
		if click then
			print("W was double tapped.")
			char.Humanoid.WalkSpeed = 20
			local playAnim = char.Humanoid:LoadAnimation(Anim)
			playAnim:Play()
			return
		end
		click = true
		wait(0.4)
		click = false
	end
end)

game:GetService("UserInputService").InputEnded:connect(function(input1)
	if input1.KeyCode == Enum.KeyCode.W then
		char.Humanoid.WalkSpeed = 16
	end
end)

1 comment

0

sorry i didn't understand what you mean, what is wrong?

1 answer

✓ Accepted answer

You need to set click back to false. Otherwise, it will stay true forever, confusing your script. I redid the code so that there are two variables, making it easier for the script. New Code:

isPressing = false
click = false
locplay = game.Players.LocalPlayer
human = locplay.Character.Humanoid
char = locplay.Character
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://1453429139"
game:GetService("UserInputService").InputBegan:connect(function(input1)
    if click then
	isPressing = true
    end
    if input1.KeyCode == Enum.KeyCode.W then
        if isPressing then
            print("W was double tapped.")
            char.Humanoid.WalkSpeed = 20
            local playAnim = char.Humanoid:LoadAnimation(Anim)
            playAnim:Play()
            return
        end
        click = true
        wait(0.4)
        click = false
    end
end)

game:GetService("UserInputService").InputEnded:connect(function(input1)
    if input1.KeyCode == Enum.KeyCode.W then
	  if isPressing then
	  	isPressing = false
	  	char.Humanoid.WalkSpeed = 16
	  end
    end
end)

2 comments

0

Thanks you, this is exactly what I was looking for.

0

np

This discussion is preserved as it was. New answers, comments, and votes are closed.