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

This script works for sprinting but stops after I click any other key. Is there any way to fix this?

Asked by 4 years ago

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)
0
Did you make this script or is a free model? DrShockz 233 — 4y
0
I took some of it from a old free Model and then i edited it to try to make it work. XenosAlt 2 — 4y

Answer this question