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

How do I have an animation be able to play if left shift is held down and the character is running?

Asked by 5 years ago

I have an animation in which I want it to play when the player holds down left shift and ONLY when they are running. If they are holding it down and they jump, fall, or have any other movement different from running then the animation will end and it will play the animations I have for falling, jumping, and so on. I did make it so if left shift is held down the animation plays, but I can't get it so that the animation can only play when the player is running. Right now I have code put it for it to work when the player falls, and I tried it, but it didn't work. Here is my code.

local character = script.Parent

boostanim = character.Humanoid:LoadAnimation(character.BoostAnimation)

local humanoid = character:WaitForChild("Humanoid")

speed = character.Humanoid.WalkSpeed

game:GetService("UserInputService").InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then if speed > 0 then boostanim:Play() humanoid.FallingDown:Connect(function(isActive) -- I tried to make it work with falling input.KeyCode = input.KeyCode.BackSpace end)

end

end

end)

game:GetService("UserInputService").InputEnded:connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then boostanim:Stop() end

end)

1 answer

Log in to vote
1
Answered by
xEmmalyx 285 Moderation Voter
5 years ago

I haven't really tested it but if I'm correct then this should be what you're looking for


local character = script.Parent local humanoid = character:WaitForChild("Humanoid") local boostanim = humanoid:LoadAnimation(character.BoostAnimation) game:GetService("UserInputService").InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then local fall = character.HumanoidRootPart.Velocity.Y local speed = character.Humanoid.WalkSpeed if speed > 16 and fall == 0 then boostanim:Play() end end end) game:GetService("UserInputService").InputEnded:Connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then boostanim:Stop() end end)
0
It didn't work. It looks like it should've though. I got rid of the old script to test this one so they didn't interfere with each other and this script didn't work. I also realized when testing that the velocity doesn't change when falling or jumping. benawesomeness8954 0 — 5y
0
Are you sure it didn't change when jumping or falling? Did the other values change? Try having a script print it or use Server side view instead of client. xEmmalyx 285 — 5y
Ad

Answer this question