My animation scripts is behaving oddly

Hello. So this is the script for the GUI button that starts the animation.
But when the player presses the animation button once, they have to click it again to stop the animation in order to be able to reselect it, so they can’t quickly press the same button multiple times. Please, could you help?

end)

local player = game.Players.LocalPlayer

local character = player.Character

repeat wait()

character = player.Character

until character

local hum = character:WaitForChild("Humanoid")

local spin = hum:LoadAnimation(script.Parent.Spin)

playing = false

script.Parent.MouseButton1Click:connect(function()

if playing == false then

spin:Play()

playing = true

elseif playing == true then

spin:Stop()

playing = false

end

You could change this to simplify:

local character = player.Character or player.CharacterAdded:Wait()

Also you can change:

to just

else

Finally, instead of depending on a boolean you can rewrite that entire if-else statement to

if spin.IsPlaying then
   spin:Stop()
else
   spin:Play()
end
1 Like

My question is, do you want the animation to restart everytime you press it? If so:

script.Parent.MouseButton1Click:Connect (function()
   spin:Stop()
   spin:Play() -- no if-else statement needed
end)
1 Like

Thank!
Мне нужно набрать больше букв, не обращайте на это внимания