Animation script not changing animation correctly/smoothly

Im currently trying to make an animation script that changes from walking to running anamations. I can’t get the animation to start up correctly.

local player = game.Players.LocalPlayer

local character = player.Character

repeat wait() until character

character.Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function(speed)
	if speed ~= 16 then	
		character.Animate.walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/?id=5941443471"
	elseif speed == 16 then
		character.Animate.walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/?id=5941419010"
	end
end)
1 Like

Try adding an animation or two inside the script. Put the IDs in them and try this script

local player = game.Players.LocalPlayer

local character = player.Character

local humanoid = character:WaitForChild("Humanoid")

local animation = script.Parent.Animation
local secondAnimation = script.Parent.SecondAnimation

local doAnim = humanoid:LoadAnimation(animation)
local doSecondAnim = humanoid:LoadAnimation(secondAnimation)

repeat wait() until character

character.Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function(speed)
	if speed ~= 16 then	
		doAnim:Play()
        doSecondAnim:Stop()
	elseif speed == 16 then
		doAnim:Stop()
        doSecondAnim:Play()
	end
end)
1 Like

Or.
Copy and paste the Animate script and inside of it replace the walkAnim ID with your anim ID.

1 Like

Hmm, I tried this it seems to do the same glitch as it was doing. Want me to show a video? I will have to add the video tomorrow as it is late.

1 Like

yes please, add a video, or an image

1 Like

It seems like it works for a little bit, but then it doesn’t work at all

1 Like

Okay, so I got the animation to change when walking to running but it only changes when you either, stop, jump, or fall. But when I stop holding shift and I don’t stop walking the animation won’t change. This is the closest I have gotten. I tried the script you made in the video above and it doesn’t seem to swap smoothly or at all. Here is your script I edited:

local player = game.Players.LocalPlayer

local character = player.Character

local humanoid = character:WaitForChild("Humanoid")

local animation = script.Animation.AnimationId
local secondAnimation = script.SecondAnimation.AnimationId

repeat wait() until character

character.Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
	if character.Humanoid.WalkSpeed == 24 then	
		character.Animate.walk.WalkAnim.AnimationId = animation
	elseif character.Humanoid.WalkSpeed == 16 then
		character.Animate.walk.WalkAnim.AnimationId = secondAnimation
	end
end)

Here is how it looks currently:

2 Likes