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

How To Make A Double Tap W Script to Sprint that Runs animations and stops them?

Asked by 4 years ago
Edited 4 years ago

I've been trying to make a script that will Sprint and play the animation on the player pressing W twice. I am also having trouble trying to find out how to make the animation stop after the player is done holding the double W. I also need to know how to make the walkspeed and camera zoom go back to normal after the holding is lifted.


local player = game.Players.LocalPlayer repeat wait() until player.Character.Humanoid local humanoid = player.Character.Humanoid local mouse = player:GetMouse() local anim = Instance.new("Animation") anim.AnimationId = "http://www.roblox.com/asset/?id=4681457024" local keyConnection = mouse.KeyUp:connect(function (key) end) local DoubleDebounce = false local UserInputService = game:GetService('UserInputService') local TargetKeyCode = Enum.KeyCode.W UserInputService.InputBegan:Connect(function(input,gameEvent) if not gameEvent and input.KeyCode == TargetKeyCode then if not DoubleDebounce then DoubleDebounce = true spawn(function() wait(1) --Interval of time where the player can double tap a key DoubleDebounce = false end) elseif DoubleDebounce then local playAnim = humanoid:LoadAnimation(anim) playAnim:Play() for i = 1,5 do game.Workspace.CurrentCamera.FieldOfView = (70+(i*2)) wait() end game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 24 repeat wait () until false == false DoubleDebounce = false keyConnection:disconnect() game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 for i = 1,5 do game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) wait() end end end end)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Try moving that keyconnect function before the for loop and have it change a running function. When the running function is false, stop repeating wait() and decrease the speed and Fov.

Running = false

local DoubleDebounce = false
    local UserInputService = game:GetService('UserInputService')
    local TargetKeyCode = Enum.KeyCode.W

    UserInputService.InputBegan:Connect(function(input,gameEvent)
        if not gameEvent and input.KeyCode == TargetKeyCode then
            if not DoubleDebounce then
                DoubleDebounce = true
                spawn(function()
                    wait(1) --Interval of time where the player can double tap a key
                    DoubleDebounce = false
                end)
            elseif DoubleDebounce then
        local playAnim = humanoid:LoadAnimation(anim)
   playAnim:Play()
Running = true
  local keyConnection = mouse.KeyUp:connect(function (key)
Running = false
end)
      for i = 1,5 do
                game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
                wait()
                end
            game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 24
            repeat wait () until Running == false
            DoubleDebounce = false
            keyConnection:disconnect()
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
            for i = 1,5 do
                game.Workspace.CurrentCamera.FieldOfView = (80-(i*2))
                wait()
            end
        end
    end
    end)
0
Thank you so much you helped a ton!! XenosAlt 2 — 4y
0
Accept his answer XenosAlt EnzoTDZ_YT 275 — 4y
Ad

Answer this question