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

How come my script breaks whenever I jump but works fine when I walk?

Asked by 4 years ago

This script is supposed to make it so that if I try to jump or walk as the animation plays nothing will happen but after the animation is done i can. It works when only walking is involved but whenever i jump before or after the animation i can no longer play the animation. Help?

Player = game.Players.LocalPlayer Tool = script.Parent.Parent Animation = script:WaitForChild("Animation") Enabled = true Tool.Equipped:Connect(function(mouse) mouse.KeyDown:Connect(function(key)

    if not Enabled then return end
    Enabled = false



    if key == "j" then
    local Humanoid = Player.Character.Humanoid
        local animationtrack = Player.Character.Humanoid:LoadAnimation(Animation)
    Humanoid.WalkSpeed = 0
    Humanoid.JumpPower = 0
        animationtrack:Play()
        wait(2)
        Humanoid.WalkSpeed = 20
    Humanoid.JumpPower = 20


    wait(.5)
        Enabled = true
    end
end)

end)

1 answer

Log in to vote
0
Answered by 4 years ago

Check to see if this works

Player = game.Players.LocalPlayer
Tool = script.Parent.Parent
Animation = script:WaitForChild("Animation") 
Enabled = true

Tool.Equipped:Connect(function(mouse)
    mouse.KeyDown:Connect(function(key)
        if not Enabled then return end
        Enabled = false

        if key == "j" then
            local Humanoid = Player.Character.Humanoid
            local animationtrack = Player.Character.Humanoid:LoadAnimation(Animation)
            Humanoid.WalkSpeed = 0
            Humanoid.JumpPower = 0
            animationtrack:Play()
            wait(2)
            Humanoid.WalkSpeed = 20
            Humanoid.JumpPower = 20

            wait(.5)
        end

        Enabled = true --//Took it outside the if statement so if the key isn't j, it can actually reset.
    end)
end)
Ad

Answer this question