After animation has stopped, character "tweens" to original cframe

I’m playing an animation for the player to enter the closet but the player character just moves back to the original position, how do I fix this. I’ve tried using PlayerEnterAnimation:AdjustWeight(0, 0) as told to do so to fix this issue in [SOLVED] Animation rotates weirdly after playing - Help and Feedback / Scripting Support - Developer Forum | Roblox but it didn’t help.

Heres my code portion:

Player.Character.HumanoidRootPart.CFrame = Wardrobe.Base.AnimationStart.WorldCFrame;
Player.Character.HumanoidRootPart.Anchored = true;

local WardrobeEnterAnimation = WardrobeAnimator:LoadAnimation(WardrobeAnimations.Enter);
local PlayerEnterAnimation = PlayerAnimator:LoadAnimation(PlayerWardrobeAnimations.Enter);

WardrobeEnterAnimation:Play();
PlayerEnterAnimation:Play();
PlayerEnterAnimation.Stopped:Once(function()
	PlayerEnterAnimation:AdjustWeight(0, 0);
end);

Try to change the character’s position after the animation by doing this:


Player.Character.HumanoidRootPart.Anchored = true;

local WardrobeEnterAnimation = WardrobeAnimator:LoadAnimation(WardrobeAnimations.Enter);
local PlayerEnterAnimation = PlayerAnimator:LoadAnimation(PlayerWardrobeAnimations.Enter);

WardrobeEnterAnimation:Play();
PlayerEnterAnimation:Play();
PlayerEnterAnimation.Stopped:Once(function()
	PlayerEnterAnimation:AdjustWeight(0, 0)
       Player.Character.HumanoidRootPart.CFrame = Wardrobe.Base.CFrame
end)

I’ve added an extra attachment for where the player will be teleported to.
Here’s the end result:

It still doesn’t work, I’ve even tried implementing the AdjustWeight(0, 0) again to see if it would work again. (It didn’t)

What you should do is wait until the animation is almost finished. Something like this (I haven’t tested it, but hopefully you get the idea). Then when it’s almost finished, set the animation speed to 0 so the animation basically freezes right at the end, keeping the player in place.

WardrobeEnterAnimation:Play()
task.wait(WardrobeEnterAnimation.Length * - 0.1)
WardrobeEnterAnimation:AdjustSpeed(0)

When I print WardrobeEnterAnimation.Length it returns 0, I don’t think this method would work for this animation… :neutral_face:

It should work for your animation, .Length always returns the length of the animation

Edit: Should you be checking the PlayerEnterAnimation variable? Also, why do you have 2 animation tracks?

Still printing 0, in the documentation for animation tracks it says for getting Length:

This will return 0 until the animation has fully loaded and thus may not be immediately available.

I have 2 animations for the wardrobe doors and for the player enter.

Does the HumanoidRootPart remain outside the closet? I’m thinking that it does that because your animation walks the character inside the closet, and when it’s done, the animation stops and everything goes back to the default “no animation playing” state and that’s why it’s doing that.

Easy fix would be to create another animation where it’s just the last frame of the entering animation (the final pose with the character inside the closet), set it to Loop, then play this animation as the entry animation ends. Of course this means the rootpart is still outside the closet, but if this fixes it, then that was your problem.

I found that making a marker right when the player animates inside the closet/wardrobe and using Animation:GetMarkerReachedSignal("Inside"):Connect() then pausing the animation, works very nicely. Thank you for your help!

1 Like

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