Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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)
0
sorry i didn't understand what you mean, what is wrong? caipira 29 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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)
0
Thanks you, this is exactly what I was looking for. Revisedy 23 — 6y
0
np User#20158 0 — 6y
Ad

Answer this question