so i made this script and when i stop walking and then restart it play walk anim ,not sprint anim
local UserInputService = game:GetService("UserInputService") local character = script.Parent local humanoid = character:WaitForChild("Humanoid") local sprintAnim = humanoid:LoadAnimation(script:WaitForChild("SprintAnim")) local isSprinting = false humanoid.Running:Connect(function(speed) if speed > 0 then sprintAnim:AdjustSpeed(1) else sprintAnim:Stop() end end) UserInputService.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then if not isSprinting then isSprinting = true sprintAnim:Play() sprintAnim:AdjustSpeed(0) humanoid.WalkSpeed = 26 humanoid.JumpPower = 50 else sprintAnim:Stop() humanoid.WalkSpeed = 16 humanoid.JumpPower = 50 isSprinting = false end end end)
you need to play the animation whenever the character starts running, not just when the player presses shift
humanoid.Running:Connect(function(speed) if speed > 0 then if isSprinting and not sprintAnim.IsPlaying then sprintAnim:Play() end sprintAnim:AdjustSpeed(speed/26) -- pretty sure you'd want the animation's playback speed to change based on how fast the player is actually walking else sprintAnim:Stop() end end)
also, the player could press shift when they're standing still, so you'd need to check for that to make sure the sprinting animation doesn't play while they're not moving
UserInputService.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then if not isSprinting then isSprinting = true if humanoid.MoveDirection.Magnitude > 0 then -- just checking the player's MoveDirection is the easiest way to tell if they're not pressing any movement keys sprintAnim:Play() sprintAnim:AdjustSpeed(0) end humanoid.WalkSpeed = 26 humanoid.JumpPower = 50 else sprintAnim:Stop() humanoid.WalkSpeed = 16 humanoid.JumpPower = 50 isSprinting = false end end end)
u need to put a local script in startercharacterscript with a animation in it to test it