Animation Pause/Play Issue

Hello!
I’ve recently got a problem with Stopping the animation and then Start to play the animation again. I re-did the script of it to add a new feature but now it doesn’t work at all. I tried to find the root cause of this and appears to be stopping the animation when I set the speed to 0, and doesn’t resume when I set the speed to 1.

The Code:

for i, TrainCar in pairs(TRAIN:GetChildren()) do
		if TrainCar:IsA("Model") then
			for i, Door in pairs(TrainCar:GetChildren()) do
				if TRAIN.DoorDirection1.Value == true then

					if Door.Name == "Doors11" then
						if TrainCar.Body.DoorDetection1.On.Value == true then
							Door.HumaniodRootPart.CanCollide = false
							local Anim = Door.AnimationController:LoadAnimation(Door.Animation)
							Anim:Play()
							print(Anim.Speed)
						end
					end
					if Door.Name == "Doors12" then
						if TrainCar.Body.DoorDetection2.On.Value == true then

							Door.HumaniodRootPart.CanCollide = false
							local Anim = Door.AnimationController:LoadAnimation(Door.Animation)
							Anim:Play()
						end
					end


				else
					if Door.Name == "Doors21" then
						if TrainCar.Body.DoorDetection1.On.Value == true then
							Door.HumaniodRootPart.CanCollide = false
							local Anim = Door.AnimationController:LoadAnimation(Door.Animation)
							Anim:Play()
						end

					end
					if Door.Name == "Doors22" then
						if TrainCar.Body.DoorDetection2.On.Value == true then

							Door.HumaniodRootPart.CanCollide = false
							local Anim = Door.AnimationController:LoadAnimation(Door.Animation)
							Anim:Play()
						end
					end
				end
			end
		end
	end


	task.wait(15)

	for i, TrainCar in pairs(TRAIN:GetChildren()) do
		if TrainCar:IsA("Model") then
			for i, Door in pairs(TrainCar:GetChildren()) do
				if TRAIN.DoorDirection1.Value == true then

					if Door.Name == "Doors11" then
						if TrainCar.Body.DoorDetection1.On.Value == true then
							Door.HumaniodRootPart.CanCollide = false
							local Anim = Door.AnimationController:LoadAnimation(Door.Animation)
							Anim:AdjustSpeed(0)
						end
					end
					if Door.Name == "Doors12" then
						if TrainCar.Body.DoorDetection2.On.Value == true then

							Door.HumaniodRootPart.CanCollide = false
							local Anim = Door.AnimationController:LoadAnimation(Door.Animation)
							Anim:AdjustSpeed(0)
						end
					end


				else
					if Door.Name == "Doors21" then
						if TrainCar.Body.DoorDetection1.On.Value == true then
							Door.HumaniodRootPart.CanCollide = false
							local Anim = Door.AnimationController:LoadAnimation(Door.Animation)
							Anim:AdjustSpeed(0)
						end

					end
					if Door.Name == "Doors22" then
						if TrainCar.Body.DoorDetection2.On.Value == true then

							Door.HumaniodRootPart.CanCollide = false
							local Anim = Door.AnimationController:LoadAnimation(Door.Animation)
							Anim:AdjustSpeed(0)
						end
					end
				end
			end
		end
	end

	task.wait(Time)
	for i, TrainCar in pairs(TRAIN:GetChildren()) do
		if TrainCar:IsA("Model") then
			for i, Door in pairs(TrainCar:GetChildren()) do
				if TRAIN.DoorDirection1.Value == true then

					if Door.Name == "Doors11" then
						if TrainCar.Body.DoorDetection1.On.Value == true then
							Door.HumaniodRootPart.CanCollide = true
							local Anim = Door.AnimationController:LoadAnimation(Door.Animation)
							Anim:AdjustSpeed(1)
							print("Speed: "..Anim.Speed)
							print(Anim.IsPlaying)
							print("TP: "..Anim.TimePosition)
						end
					end
					if Door.Name == "Doors12" then
						if TrainCar.Body.DoorDetection2.On.Value == true then

							Door.HumaniodRootPart.CanCollide = true
							local Anim = Door.AnimationController:LoadAnimation(Door.Animation)
							Anim:AdjustSpeed(1)
						end
					end


				else
					if Door.Name == "Doors21" then
						if TrainCar.Body.DoorDetection1.On.Value == true then
							Door.HumaniodRootPart.CanCollide = true
							local Anim = Door.AnimationController:LoadAnimation(Door.Animation)
							Anim:AdjustSpeed(1)
						end

					end
					if Door.Name == "Doors22" then
						if TrainCar.Body.DoorDetection2.On.Value == true then

							Door.HumaniodRootPart.CanCollide = true
							local Anim = Door.AnimationController:LoadAnimation(Door.Animation)
							Anim:AdjustSpeed(1)
						end
					end
				end
			end
		end
	end

Output of the Print:
image

1 Like
local Anim = Door.AnimationController:LoadAnimation(Door.Animation)
Anim:AdjustSpeed(1)
print("Speed: "..Anim.Speed)
print(Anim.IsPlaying)
print("TP: "..Anim.TimePosition)

Could it be because you’re never calling Anim:Play() here? Loading the animation and then adjusting it’s speed wont make it play

I am calling Anim:Play() in the beginning of the function before the task.wait(). Then just pausing it for X seconds defined before the animation part in this function.

1 Like

Yeah but that’s in a different scope and you’re reinitiating the variable so you called Play() on a different animationTrack

The problem is, the animation pauses in the second part of the animation function, but doesn’t resume. And I can’t have a wait function in the for loop.

1 Like

Which part specifically is the second part of the animation function? And where are you calling Play(), and then trying to pause & resume it? (Sorry, there’s just a lot of code and it’s a bit confusing to trace :stuck_out_tongue: )

I have just found out the issue, it was that I am calling the local Anim again, I see on my old code right now that i used another method to check when to resume the anim.

Appriciate your help! It was just me who coded a bit too fast without thinking haha. You have a good day!

1 Like

So you were overriding the old animation track? That was the issue?

Yes, that is correct.

/////////////

1 Like

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