Stopping an animation?

Hi developers. Just trying to make an animation gui and the animation is not stopping.

Here is the script:

local animation

for _, button in pairs(script.Parent.ScrollingFrame:GetChildren()) do
	if tonumber(button.Name) ~= nil then
		button.Text = (game:GetService("MarketplaceService"):GetProductInfo(tonumber(button.Name)).Name)
		button.Text = string.lower(button.Text)
		button.MouseButton1Click:Connect(function()
			if button.Name == "Stop" then
				if animation ~= nil then animation:Stop()
			else
				local animobj = Instance.new("Animation")
				animobj.AnimationId ="http://www.roblox.com/asset/?id=" .. button.Name
				animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(animobj)
				animation.Looped = true
				animation:Play()
			end
			
		end)
	end
	
end

Thanks!

(oml I just tried to ctrl+k my download bar away)

You’re missing an end in that if statement

Edit : Try printing to see if it actually reaches the block

Updated, still not working.

local animation

for _, button in pairs(script.Parent.ScrollingFrame:GetChildren()) do
	if tonumber(button.Name) ~= nil then
		button.Text = (game:GetService("MarketplaceService"):GetProductInfo(tonumber(button.Name)).Name)
		button.Text = string.lower(button.Text)
		button.MouseButton1Click:Connect(function()
			if button.Name == "Stop" then
				if animation ~= nil then animation.Looped = false animation:Stop() end
			else
				local animobj = Instance.new("Animation")
				animobj.AnimationId ="http://www.roblox.com/asset/?id=" .. button.Name
				animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(animobj)
				animation.Looped = true
				animation:Play()
			end
			
		end)
	end
	
end

Ok, I’m an idiot. The button isn’t actually called “Stop”.
:man_facepalming: