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

How can I keep a sprinting animation running when I press something like Shift + D?

Asked by 1 year ago
I'm making a survival game and began working on custom animations, and while I was abel to get the animation to run when you press Shift and stop when you let go, it also stops when you press something, jump or click anything while running, whether you're you're still holding Shift or not. This is less of a small help, but more of a favor to ask if someone can show me how to do that, because I simply don't know. Here's what I'm working with by the way: (Local script in StarterPlayerScripts).
local GatherShortestAnimation = script.GatherTall
local player = game.Players.LocalPlayer
local char =  player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local GatherShortestAnimationTrack = hum.Animator:LoadAnimation(GatherShortestAnimation)
local canSprint = false
local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(Input, gameprocess)
    if not gameprocess then
        if Input.KeyCode == Enum.KeyCode.LeftShift then
        GatherShortestAnimationTrack:Play()
        end
    end
end)

uis.InputEnded:Connect(function(Input, gameprocess)
        GatherShortestAnimationTrack:Stop()
end)

I would really apreciate it if I could get some help on this, thanks!

1 answer

Log in to vote
0
Answered by 1 year ago

perhaps for this part

uis.InputEnded:Connect(function(Input, gameprocess)
    GatherShortestAnimationTrack:Stop()
end)

you can try

uis.InputEnded:Connect(function(Input, gameprocess)
    if Input.KeyCode == Enum.KeyCode.LeftShift then
        GatherShortestAnimationTrack:Stop()
    end
end)

1
Thank you! I'm not quite sure how this works, but it does! The only thing I need to do now is make a jump and fall animation and I really hope the running animation will play after landing! AbettrWesley 6 — 1y
Ad

Answer this question