I've created a script that teleports the player in the direction (only x and z value) they're looking at when they press E on the keyboard. It plays the animation like intended, but if the player changes their animation (i.e. Presses E while running, then stops before the animation finishes), the animation is replaced by the newly loaded idle animation. How can I make sure that the custom animation fully finishes before loading the default animations for running, idle, etc.?
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportEvent = Instance.new("RemoteEvent", ReplicatedStorage)
TeleportEvent.Name = "TeleportEvent"
local function onTeleport(plr)
local char = game.Workspace:FindFirstChild(plr.Name)
local Trail = game.Workspace.Trail:Clone()
local Trail2 = game.Workspace.Trail:Clone()
local humanoid = char.Humanoid
local animation = Instance.new("Animation")
animation.AnimationId = "http://roblox.com/asset/?id=4543906727"
local animTrack = humanoid:LoadAnimation(animation)
animTrack:Play()
wait()
Trail.Parent = char.HumanoidRootPart
local attachment0 = Instance.new("Attachment", char.HumanoidRootPart)
attachment0.Name = "TrailAttachment0"
local attachment1 = Instance.new("Attachment", char.UpperTorso)
attachment1.Name = "TrailAttachment1"
Trail.Attachment0 = attachment0
Trail.Attachment1 = attachment1
wait(1.25)
Trail:Remove()
end
TeleportEvent.OnServerEvent:Connect(onTeleport)
^This code is in a script inside of ServerScriptService
The function is called in a different script, which has some local visual effects and checks for the keyboard input.
Any help is appreciated!

3 comments
Instead of saying "local char = game.Workspace:FindFirstChild(plr.Name)" then just say local char = plr.Character
Hmm, the script still teleports the player and plays the animation, but I still have the same problem as before—the animation is stopped whenever the other animations are loaded
You can also add a debounce, so the animation can runs perfectly until the second one runs.