Animation on Loop

Hi!
In my Kpop Club Game (link to game below), I am having a bit of trouble with the wait() in the script
The issue is that when I click on the GUI button for the dance, it is on loop and I want the loop to stop once the player clicks on the button again. In addition, once I click on one of the dances I am not able to play it again when I click on another dance.

image

This is the code in the LocalScript:

wait (3)
Player = game.Players.LocalPlayer.Character
animation36 = Player.Humanoid:LoadAnimation(script.Animation36)
CanEmote = true

script.Parent.MouseButton1Click:connect(function()
local emote = math.random(1,1)
if emote == 1 and CanEmote == true then
animation36:Play()
CanEmote = false
wait(2)
CanEmote = true

end

end)

https://www.roblox.com/games/2954458986/Kpop-Club

2 Likes

@qothiu has solved this problem! Thanks!

Here is the script:

wait (3)
local Player = game.Players.LocalPlayer.Character
local animation36 = Player.Humanoid:LoadAnimation(script.Animation36)
local CanEmote = true

script.Parent.MouseButton1Click:connect(function()
local emote = math.random(1,1)
if emote == 1 then
if CanEmote == true then
animation36:Play()
CanEmote = false
else
animation36:Stop()
CanEmote = true
end
end
end)

1 Like