If you jump it doesn’t play the sprinting animation but if you walk off a ledge then it does, and idk why. Did I do something wrong? Thanks.
local userInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local runningAnimation = Instance.new("Animation")
runningAnimation.AnimationId = "rbxassetid://84945600163075"
local isSprinting = false
local runningAnimTrack
local function toggleSprint()
if isSprinting then
humanoid.WalkSpeed = 16
if runningAnimTrack then
runningAnimTrack:Stop()
end
else
humanoid.WalkSpeed = 35
if humanoid.MoveDirection.Magnitude > 0 and character.HumanoidRootPart and character.HumanoidRootPart.Material ~= Enum.Material.Air then
runningAnimTrack = humanoid:LoadAnimation(runningAnimation)
runningAnimTrack:Play()
else
humanoid.Running:Wait()
if humanoid.MoveDirection.Magnitude > 0 and character.HumanoidRootPart and character.HumanoidRootPart.Material ~= Enum.Material.Air then
runningAnimTrack = humanoid:LoadAnimation(runningAnimation)
runningAnimTrack:Play()
end
end
end
isSprinting = not isSprinting
end
userInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.LeftShift then
toggleSprint()
end
end)
humanoid.Running:Connect(function(speed)
if speed == 0 or character.HumanoidRootPart.Material == Enum.Material.Air then
if isSprinting and runningAnimTrack then
runningAnimTrack:Stop()
end
elseif speed > 0 and isSprinting and not runningAnimTrack.IsPlaying then
runningAnimTrack:Play()
end
end)
humanoid.Jumping:Connect(function()
if isSprinting and runningAnimTrack then
runningAnimTrack:Stop()
end
end)
game:GetService("RunService").Heartbeat:Connect(function()
if character.HumanoidRootPart.Material == Enum.Material.Air and runningAnimTrack then
runningAnimTrack:Stop()
end
end)