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
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