Animation not stopping on my event

I’m trying to make the animation stop on the last frame but I’m experiencing a problem with the debug output test printing but its not stopping, thanks in advance.

local tool = script.Parent
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://(ANIMATIONID)"

tool.Activated:Connect(function()
	local character = tool.Parent
	local humanoid = character:FindFirstChild("Humanoid")

	if humanoid then
		local animator = humanoid:FindFirstChildOfClass("Animator")
		if not animator then
			animator = Instance.new("Animator")
			animator.Parent = humanoid
		end

		local track = animator:LoadAnimation(animation)
		track.Priority = Enum.AnimationPriority.Action
		track.Looped = false
		
		track:GetMarkerReachedSignal("End"):Connect(function()
			print("test")
			track:Stop()
		end)
		
		track:Play()
	end
end)

What you mean by “it does not stop”. Do quick assert(track.IsPlaying == false) after track:Stop(). Maybe you want to freeze animation track at that time, so that all affected joints gets locked in some particular position/rotation. Then you should use track.AdjustSpeed(0).

		track:AdjustSpeed(0)

worked I tried that before but suddenly it works now

means, your intent was to freeze joints. Chances are that it have not worker for you, because track.Priority was lower than other tracks playing on the rig.

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