So yea the script works for sprinting but it will stop the running if I press any other key. I was wondering how to fix this problem. Thank you for reading this. :)

local player = game.Players.LocalPlayer
    local humanoid = player.Character.Humanoid
    local mouse = player:GetMouse()
    
    local anim = Instance.new("Animation")
    anim.AnimationId = "http://www.roblox.com/asset?id=4681674041"

    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 (TargetKeyCode)
                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()
            playAnim:Stop()
            game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
            for i = 1,5 do
                game.Workspace.CurrentCamera.FieldOfView = (80-(i*2))
                wait()
            end
        end
    end
end)

2 comments

0

Did you make this script or is a free model?

0

I took some of it from a old free Model and then i edited it to try to make it work.