I just want to change the walk animation and the idle animation of players whenever I want to. The problem is: due to a flaw in the roblox animating script, the animations won’t play if the previous animation is in use.
for example, if I change the walking animation, then the new animation won’t play while I am still walking. You would have to stop walking and then start walking again for it to play.
This is a serious issue in my game, because I have tons of animations and I have to do weird tricks that are probably bad practice in order to get the animations to play properly. For example, I usually put my teleport parts high in the air so the falling animation will play before the idle animation. I also force the character to stop moving and walk again.
It works fine because of my weird methods to make it work properly, but due to lag it sometimes doesn’t work, and you might end up crawling around the map when you’re not suppose to.
Please help me, because so far this is still the number 1 issue in my game.
You’ll have to load the walking animation on the Animator then :Stop() and :Play() it again. If your script changes the walking animation, this is the only way I can see you achieving this.
Sorry my bad. Also it doesn’t matter, audios and Animations both use :Stop() and :Play() so I don’t have to reference it in specific. Thanks though.
What I meant to say was try loading the previous animation using :LoadAnimation, stopping the animation, then changing it to the new animation. Load the new animation, but don’t play it. Since Roblox’s script handles the animation priorities, this should work. If this doesn’t end up working, you’ll have to write your own due to limitations with Roblox’s.
When you change the animation, what animation type do you have your animation set to? If it’s anything but Core, that explains why it just looped the walking animation. Also does it only work if you stop walking and start walking again?
I will do some personal investigation. As I said earlier, this might be due to the way Roblox has their script setup. I don’t do walking animations often, so I wouldn’t be able to help until I tried it myself
have you tried to stop all animations and animationtracks of the player before changing their animations? maybe try to reload the character after changing their animations?
There’s just one problem left though. When I use AnimationTrack:Play() then the animation will play on my character no matter what (it could play the walking animation while I am idle.) Is there a way to fix this?
I tried detecting if the player is walking or not. Is this the correct way I should do it?
if hit.Parent:FindFirstChild("Humanoid").MoveDirection == Vector3.new(0,0,0) then
local AnimationTrack = hit.Parent:FindFirstChild("Humanoid"):LoadAnimation(hit.Parent.Animate.idle.Animation1)
AnimationTrack:Play()
else
local AnimationTrack = hit.Parent:FindFirstChild("Humanoid"):LoadAnimation(hit.Parent.Animate.walk.WalkAnim)
AnimationTrack:Play()
end
repeat
task.wait()
-- Check if Sprint is already being played
if IsSprinting == true then
-- do nothing
else
IsSprinting = true
LoadedSprintAnim:Play()
end
-- Check if the player is even moving
if Humanoid.MoveDirection == Vector3.new(0, 0, 0) then
Humanoid.WalkSpeed = OriginalWalkSpeed
Humanoid.JumpPower = OriginalJumpPower
LoadedSprintAnim:Stop()
IsSprinting = false
elseif Humanoid:GetState() == Enum.HumanoidStateType.Jumping or Humanoid:GetState() == Enum.HumanoidStateType.Freefall or Humanoid:GetState() == Enum.HumanoidStateType.None or Humanoid:GetState() == Enum.HumanoidStateType.Seated then
Humanoid.WalkSpeed = OriginalWalkSpeed
Humanoid.JumpPower = OriginalJumpPower
LoadedSprintAnim:Stop()
IsSprinting = false
end
-- Check if the LeftShift is no longer being held
if LoopShouldEnd == true then
LoadedSprintAnim:Stop()
Humanoid.WalkSpeed = OriginalWalkSpeed
Humanoid.JumpPower = OriginalJumpPower
IsSprinting = false
break
end
-- Run until one of these parameters are met
until Humanoid.MoveDirection == Vector3.new(0, 0, 0) or Humanoid:GetState() == Enum.HumanoidStateType.Jumping or Humanoid:GetState() == Enum.HumanoidStateType.Freefall or Humanoid:GetState() == Enum.HumanoidStateType.Seated
It’s not my full script, just a section of it you might need reference for.