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:
My animations are on 'movement' and on 'loop'
these animations are mine and working
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()
