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

Walking and Running animations?

Asked by
Jo_Bot 67
6 years ago

I have made walking and running animations that have distinct differences, and I want it to where if you have a WalkSpeed of 12-15, use the walk animation, and 15-25 would be running.

I was able to get this kind of working, but the problem is that if I switch from walking to running or running to walking it continues the previous animation. How could I fix this?

1 answer

Log in to vote
0
Answered by
Jo_Bot 67
6 years ago

Sorry, I forgot to give my code.

local UIS = game:GetService("UserInputService")
local running = false
local WalkAnim = "rbxassetid://1580957360"
local RunAnim = "rbxassetid://1580965752"

game.Players.LocalPlayer.Character.Animate.walk.WalkAnim.AnimationId = WalkAnim
game.Players.LocalPlayer.Character.Animate.run.RunAnim.AnimationId = WalkAnim

UIS.InputBegan:connect(function(key)
    if key.KeyCode == Enum.KeyCode.LeftShift then
        running = true
        game.Players.LocalPlayer.Character.Animate.walk.WalkAnim.AnimationId = RunAnim
        game.Players.LocalPlayer.Character.Animate.run.RunAnim.AnimationId = RunAnim

        local keyConnection = UIS.InputEnded:connect(function (key)
            if key.KeyCode == Enum.KeyCode.LeftShift then
                running = false
            end
        end)
        for i = 1,5 do
            wait()
        end
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 24

        repeat wait () until running == false
        keyConnection:disconnect()
        game.Players.LocalPlayer.Character.Animate.walk.WalkAnim.AnimationId = WalkAnim
        game.Players.LocalPlayer.Character.Animate.run.RunAnim.AnimationId = WalkAnim
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 12

        for i = 1,5 do
            wait()
        end
    end
end)

Ad

Answer this question