You’ll want to put this script in the button, and make an Animation instance and parent it to the script.
--LocalScript
local Players = game:GetService("Players");
local plr = Players.LocalPlayer;
local char = plr.Character;
local hum = char:WaitForChild("Humanoid");
local anim = script:WaitForChild("Animation"); --Put an animation in this script
local track = hum:LoadAnimation(anim); --Loads the animation
script.Parent.MouseButton1Down:Connect(function()
if track.IsPlaying() then
track:Stop(); --Stops the animation if it's already playing
else
track:Play(); --Plays the animation if not
end
end)
In roblox, an instance is just an object. An animation instance looks like this
And this script already stops the animation if clicked while it’s playing.