Animation Brick Issue

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Create a brick that stops playing an animation

  2. What is the issue? I used this script below to play an animation when a player touches a brick. Assuming that it would work if I replaced :Play() with :Stop(), it would stop the animation. But it didn’t.

function onTouched(hit)
	local human = hit.Parent:findFirstChild("Humanoid")
	if human then
	local anim = human:LoadAnimation(script.Parent.Animation)
	anim:Play()
	end
end
script.Parent.Touched:connect(onTouched)
  1. What solutions have you tried so far? I tried looking on the Dev Forum or watching videos but couldn’t find anything

Thanks!

function onTouched(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local humanoid = hit.Parent:FindFirstChild("Humanoid")
		local animator = humanoid:WaitForChild("Animator")
		local anim = animator:LoadAnimation(script.Parent:WaitForChild("Animation"))
		anim:Play()
	end
end

script.Parent.Touched:connect(onTouched)
function onTouched(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local humanoid = hit.Parent:FindFirstChild("Humanoid")
		local animator = humanoid:WaitForChild("Animator")
		local anim = animator:LoadAnimation(script.Parent:WaitForChild("Animation"))
		anim:Stop()
	end
end

script.Parent.Touched:connect(onTouched)

Have 2 parts, one which starts the animation & another which stops the animation. Place each script in each part.

It causes an error saying that there is no Animator found in the Humanoid

local animator = humanoid:WaitForChild("Animator")
Remove both of these lines from the 2 scripts.

So would I replace the anim variable with humanoid instead of animator?

After doing this it still did not work.

Mind sharing the animation being used for testing?

Animation