Why does the animation not stop?

I’m trying to make a computer hacking system, the animation works. But when I move my character it doesn’t stop the animation neither make the ProximityPrompt visible again. You will understand down below in the code:
image
ComputerModule:

local computerModule = {}

function computerModule.ActivateComputers(computerFolder)
	for _, computer in pairs(computerFolder:GetChildren()) do
		if not computer:FindFirstChild("ProximityPrompt") then local PP = Instance.new("ProximityPrompt", computer) end
		
		computer:FindFirstChild("ProximityPrompt").Triggered:Connect(function(plr)
			computer.ProximityPrompt.Enabled = false
			local HackingAnimation = script:WaitForChild("HackingAnim")
			wait()
			local Character = plr.Character
			local Humanoid = Character.Humanoid
			local HackingAnimationTrack = Humanoid:LoadAnimation(HackingAnimation)
			
			while wait(1.10) do
				HackingAnimationTrack:Play()
			end
			
			if Humanoid.MoveDirection.Magnitude > 0 then
				HackingAnimationTrack:Stop()
				computer.ProximityPrompt.Enabled = true
			end
			
		end)
	end
end

return computerModule

Output:

local ComputerModule = require(script.ComputerModule)
if workspace:FindFirstChild("ComputerFolder") then
	ComputerModule.ActivateComputers(workspace.ComputerFolder)
else
	warn("ComputerFolder unavailable")
end

Sorry, I might go offline… Please send your answer down. I’ll also appreciate for any types of help :slight_smile:

1 Like

Loops yield threads, your loop isn’t inside a wrapper

coroutine.wrap(function()
   while wait(1.10) do
      if computer.ProximityPrompt.Enabled then
         break -- stop the loop if the player walked away
      end

	  HackingAnimationTrack:Play()
   end
end)()
1 Like

Sorry, it was late at night so I had to go. I’ll check if it works!

this will cause it to loop play infinitely, so when you stop it it’ll just play again.

1 Like

Oh, I forgot about breaking the loop. Let me try.

Both thanks to @Shm_kle and @HugeCoolboy2007 for helping me out!

1 Like