Sprint animation bug

So im making a sprint system for a custom character and i found a bug:


So the problem is that when you stop sprinting the run animation continue to play until u stop walking
Here’s the script:

UserInputService.InputBegan:Connect(function(input)
   if input.KeyCode == Enum.KeyCode.ButtonL3 then
		if sprint == false then
			Character:WaitForChild("Humanoid").WalkSpeed = 15
			sprint = true
			if pose == "Walking" then
				playAnimation("run", 0.3, Humanoid)
				setAnimationSpeed(1)
				pose = "Running"
			end
		else
			Character:WaitForChild("Humanoid").WalkSpeed = 8
			sprint = false
			if pose == "Running" then
				playAnimation("walk", 0.3, Humanoid)
				setAnimationSpeed(1)
				pose = "Walking"
			end
		end
	end
end)

Can somebody help me?

1 Like

Here’s the pose script and the move function:

elseif (pose == "Running") then
		playAnimation("run", 0.9, Humanoid)
		if UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter then		
			if not wasStrafe then
				doForAllRunTracks(function(trackRec, name)
					trackRec.track:AdjustWeight(smallButNotZero, blendTime)
					trackRec.lastWeight = smallButNotZero							
				end)				
			end
			setRunSpeed()
			wasStrafe = true
		else
			if wasStrafe then
				doForAllRunTracks(function(trackRec, name)
					trackRec.track:AdjustWeight(smallButNotZero, blendTime)
					trackRec.lastWeight = smallButNotZero							
				end)
				setRunSpeed()		
				wasStrafe = false
			end
		end	
	elseif (pose == "Walking") then
		playAnimation("walk", 0.9, Humanoid)
		if UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter then		
			if not wasStrafe then
				doForAllRunTracks(function(trackRec, name)
					trackRec.track:AdjustWeight(smallButNotZero, blendTime)
					trackRec.lastWeight = smallButNotZero							
				end)				
			end
			setRunSpeed()
			wasStrafe = true
		else
			if wasStrafe then
				doForAllRunTracks(function(trackRec, name)
					trackRec.track:AdjustWeight(smallButNotZero, blendTime)
					trackRec.lastWeight = smallButNotZero							
				end)
				setRunSpeed()		
				wasStrafe = false
			end
		end	
function onMoving(speed)	
	if speed > 0 then
		if speed > 8 then
			playAnimation("run", 0.3, Humanoid)
			setAnimationSpeed(1)
			pose = "Running"
		else
			playAnimation("walk", 0.3, Humanoid)
			setAnimationSpeed(1)
			pose = "Walking"
		end
	else
		if emoteNames[currentAnim] == nil and not currentlyPlayingEmote then
			playAnimation("idle", 0.2, Humanoid)
			pose = "Standing"
		end
	end
end
1 Like

My bad it was an easy fix, i just need to change

if speed == 8 then
--
end

to

if speed == 7 then
--
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.