How to play an animation only once?

Well, I have a problem and it is that the action animation plays many months and I have to stop it with the same script, but it is frustrating to have to check the waiting time to stop it

local PlayAnim = script.Parent:WaitForChild("PlayAnim")
local Value = script.Parent:WaitForChild("Acción")
local Debounce2 = false
local tool = script.Parent

local function mine()
if not Debounce2 then
			local Character = script.Parent.Parent
			local AnimationTrack = Character:WaitForChild("Humanoid"):LoadAnimation(PlayAnim)
			Debounce2 = true
			AnimationTrack:Play()
			wait(0.33)
			Value.Value = true
			AnimationTrack:Stop()
			wait(0.2)
			Value.Value = false
			wait(0.1)
			Debounce2 = false
		end
	end
tool.Activated:Connect(mine)
1 Like

Changing the .Looped property should fix this problem! Your animation will only play once and stop. Change this:

To this:

AnimationTrack.Looped = false
AnimationTrack:Play()
Value.Value = true

It does not work, it keeps activating the animation infinitely

then,
clear/overide the tracks.

local hum = hum -- put the hum path here

local AnimationTracks = hum:GetPlayingAnimationTracks()

for i, a in pairs(AnimationTracks) do
	a:Stop()
end

It does not work, I tried and no. Maybe it doesn’t work because I didn’t know what he meant by zum

Is it a server script or local script?

it’s a server script, I need it for other players to see

Unfortunately the .Looped property doesn’t replicate from the server to the client for some reason. So you have to play the animation through the clients using a RemoteEvent, changing the .Looped property and playing the animation in a LocalScript

5 Likes