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

Sprint with running and walking animations?

Asked by 4 years ago
Edited 4 years ago

Summary:

How would i create a script so if the game starts it plays my walking animation first. Then, i press left shift and it will sprint(change the player speed) while also change it to a running animations. Finally, the walking animation will start playing again as I let go of Left Shift.

Info:

  1. My animations are on 'movement' and on 'loop'

  2. these animations are mine and working

  3. my script is located in StarterPlayer.StarterCharacterScripts and is a local script

Here is my code i've been working with:

local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character
--run
local Run = Instance.new('Animation')
Run.AnimationId = 'rbxassetid://5013482632'
RunAnim = Character.Humanoid:LoadAnimation(Run)
--walk
local Walk = Instance.new('Animation')
Walk.AnimationId = 'rbxassetid://5013378526'
WalkAnim = Character.Humanoid:LoadAnimation(Walk)

WalkAnim:Stop()

UIS.InputBegan:connect(function(input)
 if input.KeyCode == Enum.KeyCode.LeftShift then
  Character.Humanoid.WalkSpeed = 20
  RunAnim:Play()
 end
end)

UIS.InputEnded:connect(function(input)
 if input.KeyCode == Enum.KeyCode.LeftShift then
  Character.Humanoid.WalkSpeed = 8
  RunAnim:Stop()
  WalkAnim:Play()
 end
end)
WalkAnim:Stop()


Answer this question