Trouble with sprint animation

What do I want to achieve?
I’m making a “shift to sprint” script with an animation.

What is the Issue?
There’s a weird bug with the animation… It plays with no problem, but when I jump or fall, the animation becomes faster.

What solutions have you tried so far?
I tried to check if it’s something in the “Animate” script, but it’s too advanced for me so I didn’t understand anything…

image

Sprinting Test:

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Running = false

UIS.InputBegan:Connect(function(input, processed)
	
	if input.UserInputType == Enum.UserInputType.Keyboard then
		
		if input.KeyCode == Enum.KeyCode.LeftShift and Character.Humanoid.MoveDirection.Magnitude > 0 then
			
			Character.Humanoid.WalkSpeed = 25
			script.Change:FireServer(1)
			Running = true
			
		end
		
	end
	
end)

UIS.InputEnded:Connect(function(input) 
	
	if input.KeyCode == Enum.KeyCode.LeftShift and Running == true then
		
		Character.Humanoid.WalkSpeed = 16
		script.Change:FireServer(2)
		
	end
	
end)

ChangeValue:

script.Parent.Change.OnServerEvent:Connect(function(player, Value)
	
	if Value == 1 then
		
		script.Parent.Running.Value = true
		
	elseif Value == 2 then
		
		script.Parent.Running.Value = false
		
	end
	
end)

Animations:

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local Animate = Character:WaitForChild("Animate")
local Animation = script.Parent.Anim
local Anim = Animation.AnimationId
local OriginalAnim = Animate.walk.WalkAnim
local Original = Animate.walk.WalkAnim.AnimationId
local Running = script.Parent:WaitForChild("Running")

Running.Changed:Connect(function()
	
	if Humanoid.MoveDirection.Magnitude > 0 and Running.Value == true then
		
		Animate.walk.WalkAnim.AnimationId = Animation.AnimationId
		local Test2 = Humanoid:LoadAnimation(Animation)
		
		if Humanoid.MoveDirection.Magnitude > 0 then
			
			Test2:Play()
			Test2:Destroy()
			
		end
		
		while wait() do

			if Running.Value == false then
				
				Test2:Stop()
				Test2:Destroy()

			end

		end
		
	else
		
		Animate.walk.WalkAnim.AnimationId = Original
		local Test = Humanoid:LoadAnimation(OriginalAnim)
		
		if Humanoid.MoveDirection.Magnitude > 0 then

			Test:Play()
			Test:Destroy()

		end
		
	end
	
end)

I think the problem is still related to the Animate script… Also, if there’s anything I can improve in the script, I’d like to know

Thanks in advance.

1 Like

The problem could be that the animation is broken or not working.

1 Like

maybe… But how can I solve it?

can u send me the link for that animation i will then find out the problem in it
:slight_smile:

rbxassetid://8795426796 There you go

did you find out what the problem is…? lol

i founded the bug in it... lol

wow, thanks for the quick response XD

1 Like