I am trying to get my cutscene rig to play a running animation while running to its point with Humanoid:MoveTo(), but to stop when reaching the position.
My issue is that upon reaching the position, it prints that it has stopped moving, but the animation just keeps playing after calling animTrack:Stop(). I have also tried doing repeat animTrack:Stop() until not animTrack.IsPlaying but it only stopped it once and acted as if the animation track had stopped playing. Below is a video of the rig running to the point, stopping, and then running to the next point and stopping, and at both stops you can see it doesn’t stop the running animation.
Here is my script, it is a LocalScript located in StarterPlayerScripts.
wait(5)
local plr = game.Players.LocalPlayer
local char = plr.Character
char.Archivable = true
local event = game.ReplicatedStorage.PlayCutscene
local cutsceneProps = workspace.CutsceneProps
event.OnClientEvent:Connect(function(cutsceneId)
local plrClone = char:Clone()
local anim = Instance.new("Animation")
anim.Name = "Anim"
local animTrack
local runningFunc = false
local function move(pos)
if not runningFunc then
runningFunc = true
local moving = true
plrClone.Humanoid:MoveTo(pos)
coroutine.resume(coroutine.create(function()
plrClone.Humanoid.MoveToFinished:Wait()
moving = false
print("stopped moving")
end))
while moving do
print("moving")
if plrClone.Humanoid.RigType == Enum.HumanoidRigType.R15 then
anim.AnimationId = "http://www.roblox.com/asset/?id=913376220"
animTrack = plrClone.Humanoid.Animator:LoadAnimation(anim)
animTrack:Play()
wait(animTrack.Length)
else
anim.AnimationId = "http://www.roblox.com/asset/?id=180426354"
animTrack = plrClone.Humanoid.Animator:LoadAnimation(anim)
animTrack:Play()
wait(animTrack.Length)
end
end
animTrack:Stop()
wait()
runningFunc = false
end
end
if cutsceneId == "intro" then
plrClone.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
plrClone.Name = "CutsceneRig_"..plr.Name
plrClone.Humanoid.WalkSpeed = 16
plrClone.HumanoidRootPart.CFrame = (cutsceneProps.hs.tsPart.CFrame * CFrame.new(Vector3.new(0,0,10))) -- POS1
plrClone.Parent = cutsceneProps.rigs
wait(1)
move(cutsceneProps.waypoints.intro_1.Position)
wait(2)
move(cutsceneProps.waypoints.intro_2.Position)
end
end)
I have looked at quite a few other posts and it seemed no one had the exact issue as me and none of the solutions for them worked for me. I have also tried debugging quite a bit and trying different ways of stopping the animation. If anyone can help out with my issue, that would be great!