Teleporting after an animation isnt very smooth

hello! I’m making a hiding system (in lockers) however I’m having trouble with the animation. basically; immediately after the animation it should teleport you right where the torso left off at the end of the animation. While this works, it seems to teleport you back to where you were for a split second before you’re actually teleported in. I’ve tried teleporting stopping the animation and teleporting you, teleporting milliseconds before the animation ends, yet none of these seem to work.

any code will be provided if needed

2 Likes

Are you teleporting the character on the server?

The server has an out of date version of what’s happening on the client so there would be a discontinuity.

Yes, the whole script is a serverscript.

1 Like

That could be the problem then. You might want to try sending a remote event to the client and have the client teleport their own character when they get the event.

The server’s copy of the character is out of date a bit because the character is client owned and there is latency between the client and server. I’m not 100% sure if that would affect this, because while the animation is running on the client when you play it from the server, Roblox’s code might correct for the latency delay.

Ideally I think it would be best to have the client teleport themselves anyways though.

Edit: Even better would be to have the client detect when the specific animation plays and have the client code teleport their character when it finishes.

For example:

-- On the client:
local animator = -- Set to the characters animator instance
animator.AnimationPlayed:Connect(function(track)
    -- Check if track.Animation is your closet hiding Animation
    track.Ended:Wait() -- Wait for the hide to finish
    -- Then teleport the character to their torso's position
end)

TBH I prefer treebee63’s method, though both work the same.

2 Likes

Your setup currently runs on the serverside for both the animation and teleportation I assume. This is almost perfect. The only issues:

  • when you play an animation it has to send the animation play event to the client
  • after you wait for the animation to end, it has to tell the client that their cframe has changed
  • both of these events come at different times and therefore has different ping, meaning they’ll never line up.

For the smoothest experience for the player you need to do play the animation and teleport the player both on the client side. This ensures there’s no time variation between events because of ping. Since these actions happen on our own personal character, the events will replicate to all other users without needing additional steps.

2 Likes

How exactly would i teleport the player to their torso’s position at the end of the animation after the animation?

It just teleports them back due to the animation already being finished once their teleported.

1 Like

I’ve reread this a couple times I finally get it LOL. I’ll try it out.

A very smart catch. For both of the methods, you’d need to get the cframe right before the animation finishes.

One way is that you could just store the CFrame offset. I think the code would be humanoidRootPart.CFrame:ToObjectSpace(torso.CFrame) to get the offset (you’d do that in studio with the animation at it’s last frame, then put it in your code), then humanoidRootPart.CFrame *= offset to apply the offset when the animation finishes.

You could also store the animation’s CFrame every frame unless the animation is finished, then use that stored cframe, or something along those lines (ex: wait just shorter than the length of the animation, then use that).

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